@@ -708,8 +708,81 @@ completed. To enable this, set the USE_VALGRIND environment variable to
708708"helgrind" to run the Helgrind tool, or any other value to run the Memcheck
709709tool. To use "helgrind" effectively, build BIND with --disable-atomic.
710710
711+ Developer Notes for pytest runner
712+ ===
713+
714+ Test discovery and collection
715+ ---
716+ There are two distinct types of system tests. The first is a shell script
717+ tests.sh containing individual test cases executed sequentially and the
718+ success/failure is determined by return code. The second type is a regular
719+ pytest file which contains test functions.
720+
721+ Dealing with the regular pytest files doesn't require any special consideration
722+ as long as the naming conventions are met. Discovering the tests.sh tests is
723+ more complicated.
724+
725+ The chosen solution is to add a bit of glue for each system test. For every
726+ tests.sh, there is an accompanying tests_sh_*.py file that contains a test
727+ function which utilizes a custom run_tests_sh fixture to call the tests.sh
728+ script. Other solutions were tried and eventually rejected. While this
729+ introduces a bit of extra glue, it is the most portable, compatible and least
730+ complex solution.
731+
732+ Module scope
733+ ---
734+ Pytest fixtures can have a scope. The "module" scope is the most important for
735+ our use. A module is a python file which contains test functions. Every system
736+ test directory may contain multiple modules (i.e. tests_*.py files)!
737+
738+ The server setup/teardown is done for a module. Bundling test cases together
739+ inside a single module may save some resources. However, test cases inside a
740+ single module can't be executed in parallel.
741+
742+ It is possible to execute different modules defined within a single system test
743+ directory in parallel. This is possible thanks to executing the tests inside a
744+ temporary directory and proper port assignment to ensure there won't be any
745+ conflicts.
746+
747+ Parallel execution
748+ ---
749+ As mentioned in the previous section, test cases inside a single module can't
750+ be executed in parallel. To put it differently, all tests cases inside the same
751+ module must be performed by the same worker/thread. Otherwise, server
752+ setup/teardown fixtures won't be shared and runtime issues due to port
753+ collisions are likely to occur.
754+
755+ Pytest-xdist is used for executing pytest test cases in parallel using the `-n
756+ N_WORKERS` option. By default, xdist will distribute any test case to any
757+ worker, which would lead to the issue described above. Therefore, it is vital
758+ to use the `--dist loadscope` option which ensures that test cases within the
759+ same (module) scope will be handled by the same worker.
760+
761+ $ pytest -n auto --dist loadscope
762+
763+ Test selection
764+ ---
765+ It is possible to run just a single pytest test case from any module. Use
766+ standard pytest facility to select the desired test case(s), i.e. pass a
767+ sufficiently unique identifier for `-k` parameter. You can also check which
768+ tests will be executed by using the `--collect-only` flag to debug your `-k`
769+ expression.
770+
771+ Compatibility with older pytest version
772+ ---
773+ Keep in mind that the pytest runner must work with ancient versions of pytest.
774+ When implementing new features, it is advisable to check feature support in
775+ pytest and pytest-xdist in older distributions first.
776+
777+ As a general rule, any changes to the pytest runner need to keep working on all
778+ platforms in CI that use the pytest runner. As of 2023-01-13, the oldest
779+ supported version is whatever is available in EL8.
780+
781+ We may need to add more compat code eventually to handle breaking upstream
782+ changes. For example, using request.fspath attribute is already deprecatred in
783+ latest pytest.
711784
712- Maintenance Notes
785+ Maintenance Notes for legacy runner
713786===
714787This section is aimed at developers maintaining BIND's system test framework.
715788
0 commit comments