ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.81k stars 889 forks source link

pytest: DX - Support targeting specific tests using `make pytest` w/ `PYTEST_TESTS` #7681

Open s373nZ opened 1 day ago

s373nZ commented 1 day ago

This is a small PR intended to slightly improve developer experience. When running the Pytest integration testing suite locally using the command make pytest, the build system takes care of altering the local context variable PYTHONPATH to make sure contributed modules are accessible to the process. While this works great for running the entire test suite, oftentimes developers are concerned with repeatedly running a subset of the tests, the particular test relevant to the functionality they are working on, or some problematic tests which the suite reports failing.

Currently, in order to target specific tests for a pytest run, a developer might:

  1. Run make pytest
  2. Observe the output to discern and capture the computed value for PYTHONPATH
  3. Copy this value
  4. Export the value as a local PYTHONPATH variable
  5. Run pytest outside of the Makefile context and feeding in the targeted list of files and tests cases to the local command

This PR suggests supporting the pass-through of a variable named PYTEST_TESTS which defaults to tests/ and can be set in a similar fashion to PYTEST_PAR and PYTEST_OPTS. This would allow developers to skip a few steps in setting up their local environment for running pytest and enjoy some of the Makefile's sane defaults if desired. For example,

PYTEST_TESTS="tests/test_askrene.py::test_layers" make pytest

Certainly, experienced CLN developers already have more convenient workflows, so please let me know if there is a more accessible convention for this.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked: