.. _testing-and-profiling: Testing and profiling ===================== Before committing code changes, run the tests/checks from a package built from your modified source. This page collects the common checks used during |Software| development: the regular ``pytest`` suite, accuracy benchmark, and profiling and coverage checks. ``pytest`` suite ~~~~~~~~~~~~~~~~ The ``pytest`` suite is ran automatically on the GitHub Actions CI for every pull request, but it is recommended to run the tests locally before committing code changes. Install test dependencies ------------------------- Install ``pytest`` and ``pytest-benchmark`` before running the ``pytest`` suite. For more background, see the `pytest documentation `_ and the `pytest-benchmark documentation `_. .. code-block:: bash pip install pytest pip install pytest-benchmark Build and reinstall the modified package ---------------------------------------- Run tests against the package built from your current source tree. This is required for the ``tests/accuracy_tests/run_accu_test.py`` as it runs the tests on the built package rather than the source code. .. code-block:: bash python -m build python -m pip uninstall AlphaPeel -y python -m pip install dist/*.whl For more detail on building a local distribution, see :ref:`dist-install`. Run the ``pytest`` suite ------------------------ From the repository root, run: .. code-block:: bash pytest If the tests pass, the beginning of the output should look similar to this: .. code-block:: ============================================================================================ test session starts ============================================================================================= platform darwin -- Python 3.11.11, pytest-9.0.1, pluggy-1.6.0 benchmark: 5.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000) rootdir: /Users/xtang3/AlphaPeel configfile: pyproject.toml plugins: benchmark-5.2.3, memray-1.9.0 collected 16 items tests/accuracy_tests/run_accu_test.py ... [ 18%] tests/functional_tests/run_func_test.py ............. [100%] ... Run a targeted functional test ------------------------------ To run one functional test, provide the pytest node id. For example, to run ``test_files``: .. code-block:: bash pytest tests/functional_tests/run_func_test.py::TestClass::test_files Inspect failed tests and printed output --------------------------------------- When a test fails and you need to inspect printed output, add ``-s``: .. code-block:: bash pytest -s Run accuracy benchmarks ~~~~~~~~~~~~~~~~~~~~~~~ In addition to running ``pytest``, you can run the full accuracy benchmark suite. This is useful when you want to compare the impact of a new change on accuracy and runtime across the configured benchmark cases in detail. From the repository root, run: .. code-block:: python from src.accuracy_runner import run_full_accuracy_suite run_full_accuracy_suite(run_name="benchmark") This writes outputs under ``tests/accuracy_tests/outputs_benchmark`` and writes the accuracy report to ``tests/accuracy_tests/reports_benchmark/accu_report.txt``. The report is a comma-separated text file with records in the form ``file_name,label,metric_name,value``. For most accuracy metrics, ``value`` contains the population metric followed by the metrics for generations 1 to 5. Runtime is written separately as ``runtime,