In ML_Tools see: Testing_Pytest.py
The pytest
example script demonstrates several key features of the Pytest testing framework:
-
Fixtures: The script uses a fixture named
sample_data
to provide common test data that can be reused across multiple test functions. This helps reduce code duplication and enhances test maintainability. -
Parametrization: The script employs the
@pytest.mark.parametrize
decorator to run a test function with multiple sets of arguments. This allows for testing a function with various inputs without writing separate test cases for each scenario. -
Custom Markers: A custom marker
@pytest.mark.slow
is used to categorize tests. This enables selective test execution based on markers, allowing you to run specific groups of tests using the-m
option. -
Mocking: The script demonstrates how to use
unittest.mock.patch
withpytest
to replace a function with a mock. This allows for controlling the behavior of the function during the test, facilitating isolated testing of units.