Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 4e63a0f

Browse files
committed
Add developer docs for pytest system test runner
1 parent 4242586 commit 4e63a0f

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

bin/tests/system/README

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,81 @@ completed. To enable this, set the USE_VALGRIND environment variable to
658658
"helgrind" to run the Helgrind tool, or any other value to run the Memcheck
659659
tool. To use "helgrind" effectively, build BIND with --disable-atomic.
660660

661+
Developer Notes for pytest runner
662+
===
663+
664+
Test discovery and collection
665+
---
666+
There are two distinct types of system tests. The first is a shell script
667+
tests.sh containing individual test cases executed sequentially and the
668+
success/failure is determined by return code. The second type is a regular
669+
pytest file which contains test functions.
670+
671+
Dealing with the regular pytest files doesn't require any special consideration
672+
as long as the naming conventions are met. Discovering the tests.sh tests is
673+
more complicated.
674+
675+
The chosen solution is to add a bit of glue for each system test. For every
676+
tests.sh, there is an accompanying tests_sh_*.py file that contains a test
677+
function which utilizes a custom run_tests_sh fixture to call the tests.sh
678+
script. Other solutions were tried and eventually rejected. While this
679+
introduces a bit of extra glue, it is the most portable, compatible and least
680+
complex solution.
681+
682+
Module scope
683+
---
684+
Pytest fixtures can have a scope. The "module" scope is the most important for
685+
our use. A module is a python file which contains test functions. Every system
686+
test directory may contain multiple modules (i.e. tests_*.py files)!
687+
688+
The server setup/teardown is done for a module. Bundling test cases together
689+
inside a single module may save some resources. However, test cases inside a
690+
single module can't be executed in parallel.
691+
692+
It is possible to execute different modules defined within a single system test
693+
directory in parallel. This is possible thanks to executing the tests inside a
694+
temporary directory and proper port assignment to ensure there won't be any
695+
conflicts.
696+
697+
Parallel execution
698+
---
699+
As mentioned in the previous section, test cases inside a single module can't
700+
be executed in parallel. To put it differently, all tests cases inside the same
701+
module must be performed by the same worker/thread. Otherwise, server
702+
setup/teardown fixtures won't be shared and runtime issues due to port
703+
collisions are likely to occur.
704+
705+
Pytest-xdist is used for executing pytest test cases in parallel using the `-n
706+
N_WORKERS` option. By default, xdist will distribute any test case to any
707+
worker, which would lead to the issue described above. Therefore, it is vital
708+
to use the `--dist loadscope` option which ensures that test cases within the
709+
same (module) scope will be handled by the same worker.
710+
711+
$ pytest -n auto --dist loadscope
712+
713+
Test selection
714+
---
715+
It is possible to run just a single pytest test case from any module. Use
716+
standard pytest facility to select the desired test case(s), i.e. pass a
717+
sufficiently unique identifier for `-k` parameter. You can also check which
718+
tests will be executed by using the `--collect-only` flag to debug your `-k`
719+
expression.
720+
721+
Compatibility with older pytest version
722+
---
723+
Keep in mind that the pytest runner must work with ancient versions of pytest.
724+
When implementing new features, it is advisable to check feature support in
725+
pytest and pytest-xdist in older distributions first.
726+
727+
As a general rule, any changes to the pytest runner need to keep working on all
728+
platforms in CI that use the pytest runner. As of 2023-01-13, the oldest
729+
supported version is whatever is available in EL8.
730+
731+
We may need to add more compat code eventually to handle breaking upstream
732+
changes. For example, using request.fspath attribute is already deprecatred in
733+
latest pytest.
661734

662-
Maintenance Notes
735+
Maintenance Notes for legacy runner
663736
===
664737
This section is aimed at developers maintaining BIND's system test framework.
665738

0 commit comments

Comments
 (0)