Create intermediate Works with: Any AI

Testing Data Code With Pytest

Structured brief

Write tests for data transformations.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratings…

Help me test my data code. A function or transformation: [FUNCTION_CODE]. Typical inputs and edge cases I know: [INPUTS_EDGE_CASES].

Write pytest tests using small hand-made DataFrames: the normal case, empty input, missing values, duplicate keys, wrong dtypes, and an idempotence check. Show how to compare DataFrames with the testing helpers in pandas, how to use fixtures and parametrisation, and how to test that errors are raised with clear messages. Add property-style checks (row counts, totals preserved) and guidance on keeping tests fast. Provide a folder layout and a command to run the tests.

Add a complete small example: a function that fills missing values by group, three tests written out in full, and the expected output of the test run. Include a note on testing with randomness by fixing seeds, and on avoiding tests that depend on the order of rows.

Also add a short list of the tests that give the most value if time is limited, ranked, and a note on running the tests automatically on each change.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

Related prompts