How to approve multiple files in one test
June 4, 2026 ยท View on GitHub
Contents
The Scenario
Let's say that you want to test whether or not a year is a leap year for four values [1993, 1992, 1900, 2000]
But instead of testing them all in one file using verify_all
you would like to have 4 seperate approval files.
- test_file.test_name.
1993.approved.txt - test_file.test_name.
1992.approved.txt - test_file.test_name.
1900.approved.txt - test_file.test_name.
2000.approved.txt
Here is a sample of one of the .approved. files:
is Leap 1992: True
Here are 3 ways you can do this in a single test.
Method 1: Verifying Parametrized Tests
Approval tests supports parametrized tests, here is an example:
@pytest.mark.parametrize("year", [1993, 1992, 1900, 2000])
def test_scenarios(year: int) -> None:
verify(
f"is Leap {year!s}: {is_leap_year(year)!s}",
options=NamerFactory.with_parameters(year),
)
Method 2: Verify Multiple Things with Blocking
Another alternative is to simply make multiple verify() calls using the NamerFactory.with_parameters in the code.
Be aware that this will halt your test on the first verify() that fails, same as a normal assert.
year = 1992
verify(
f"is Leap {year!s}: {is_leap_year(year)!s}",
options=NamerFactory.with_parameters(year),
)
year = 1993
verify(
f"is Leap {year!s}: {is_leap_year(year)!s}",
options=NamerFactory.with_parameters(year),
)
year = 1900
verify(
f"is Leap {year!s}: {is_leap_year(year)!s}",
options=NamerFactory.with_parameters(year),
)
year = 2000
verify(
f"is Leap {year!s}: {is_leap_year(year)!s}",
options=NamerFactory.with_parameters(year),
)
Method 3: Verify Multiple Things without Blocking
To manually verify multiple things without the executation stopping on the first failure,
using gather_all_exceptions_and_throw will prevent blocking, while still failing on any failure.
Here is an example:
years = [1993, 1992, 1900, 2000]
gather_all_exceptions_and_throw(
years,
lambda y: verify(
f"is Leap {y!s}: {is_leap_year(y)!s}",
options=NamerFactory.with_parameters(y),
),
)