Testing¶
Overview¶
This page outlines our guidelines for writing tests in task scripts.
General Guidelines¶
Use
pytestto create integration and unit tests in the__tests__/integrationand__tests__/unitdirectories, respectively.For unit tests there should be 1 test module per module in the package, containing tests for the classes and functions in that module.
For integration tests there should be 1 module
test_main.pywhere snapshot tests are performed viapytest-snapshoton each example file inexample-input, using the corresponding files inexample-outputas snapshots.Each test should be split into 3 sections:
# Arrange: Set up the test data# Act: Call the code being tested# Assert: Verify the results are as expected
Test Fixtures¶
To mock UUID generation, use the
mock_uuid_generatorfixture, which is made available by addingts-lib-pytestas a dev dependency.Logs should be captured via the
caplogfixture, and asserted against in the# Assertsection of the test.We prefer to avoid mocking functions where possible, but if necessary the
mockerfixture frompytest-mockcan be used.