Testing

Overview

This page outlines our guidelines for writing tests in task scripts.

General Guidelines

  • Use pytest to create integration and unit tests in the __tests__/integration and __tests__/unit directories, 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.py where snapshot tests are performed via pytest-snapshot on each example file in example-input, using the corresponding files in example-output as 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_generator fixture, which is made available by adding ts-lib-pytest as a dev dependency.

  • Logs should be captured via the caplog fixture, and asserted against in the # Assert section of the test.

  • We prefer to avoid mocking functions where possible, but if necessary the mocker fixture from pytest-mock can be used.