Even better parameterized pytest boilerplate
✓ Published0🌍 Public
Aabehmiel
Last edited Aug 10, 2017
Created on Aug 10, 2017
This example demonstrates how to test the `is_prime` function across multiple input-output pairs using pytest’s parameterized testing. It shows a table of seven cases, ranging from negative numbers to large primes, each paired with an expected boolean result. The code uses the `@pytest.mark.parametrize` decorator to define the `x` and `output` arguments, then asserts that `is_prime(x)` matches the expected output. The test data is written directly in the decorator’s list, sourced from James Routley’s blog, and the test runs each case as a separate pytest test.
AI-generated description