I'm writing some quite complex pytest parameterized tests this morning, and I was finding it a little bit hard to read the test cases as the number of parameters grew. …
I'm writing some code that accepts webhooks from Stripe. I wanted to simulate hits to this endpoint in my Django tests. Stripe uses a Stripe-Signature
header and I wanted a way to mock my code so that I didn't need to calculate the correct signature. …
I'm a big fan of snapshot testing - writing tests where you compare the output of some function to a previously saved version, and can re-generate that version from scratch any time something changes. …
For apple-notes-to-sqlite I needed to write some tests that simulated executing the osascript
command using the Python subprocess
module. …
My test suite for Datasette has grown so large that running the whole thing sometimes causes me to run out of file handles. …
For s3-ocr issue #21 I needed to write a test that simulates what happens when Amazon Textract returns a "LimitExceededException". When using boto this error presents itself as an exception: …
I decided to add automated tests to my Datasette Lite project. Datasette Lite bundles my Datasette Python web application as a client-side application running inside WebAssembly using Pyodide. …
I was seeing this warning in a Django project when I thought I was correctly using timezone-aware dates everywhere: …
I wanted to use a fixture with pytest-asyncio
that was itsef as async def
function, so that it could execute await
statements. …
This tweet from @Mariatta tipped me off to the ability to measure "contexts" when running coverage - as a way to tell which tests exercise which specific lines of code. …
For both s3-credentials and datasette-publish-fly I have a need for real-world integration tests that actually interact with the underlying APIs (AWS or Fly) to create and destroy resources on those platforms. …
For sqlite-utils#364 I needed to write a test for a Click app which dealt with input streamed to standard input. I needed to run some assertions during that process, which ruled out the usual CliRunner.invoke() testing tool since that works by running the command until completion. …
I usually build command-line tools using Click (and my click-app cookiecutter template), which includes a really nice set of tools for writing tests. …
I needed to write a test that checked for a really complex sequence of mock calls for s3-credentials#3. …
pytest-recording is a neat pytest plugin that makes it easy to use the VCR library, which helps write tests against HTTP resources by automatically capturing responses and baking them into a YAML file to be replayed during the tests. …
I wanted to start an actual server process, run it for the duration of my pytest session and shut it down at the end. …
I got my asgi-csrf Python package up to 100% code coverage. Here's the pull request. …
While implementing more finely-grained permissions for datasette-insert-api
(issue 8) I decided I wanted to register a Datasette pluggy plugin for the duration of a single test. …
My lazy approach to writing unit tests means that sometimes I want to run an assertion against most (but not all) of a dictionary. …
I wrote this test to exercise some httpx code today, using pytest-mock. …
I habitually use the tmpdir
fixture in pytest to get a temporary directory that will be cleaned up after each test, but that doesn't work with scope="session"
- which can be used to ensure an expensive fixture is run only once per test session and the generated content is used for multiple tests. …