-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
52 lines (44 loc) · 2.23 KB
/
Copy pathconftest.py
File metadata and controls
52 lines (44 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Root conftest, kept deliberately empty of fixtures.
Its only job is the guard below. pytest loads conftest files by walking each
argument's directory chain from the repo root down to the leaf, so whichever
argument is processed first, this file is always imported before tests/conftest.py
or qt_tests/conftest.py. A pytest_sessionstart hook would be too late: all initial
conftests, including qt_tests/conftest.py's module-level harness.bootstrap() call,
finish loading before pytest_sessionstart ever fires. Plain module-level code here
catches every command-line invocation, which covers every documented and CI path;
it reads sys.argv, so it cannot see a dual-path invocation that never puts tests/
and qt_tests/ there, such as a programmatic pytest.main(['tests', 'qt_tests']).
tests/ and qt_tests/ cannot share a process: both install a Qt into aqt.qt, and
whichever lands first wins for every internpearls import for the rest of the run.
"""
import os
import sys
_ROOT = os.path.dirname(os.path.abspath(__file__))
_TESTS = os.path.join(_ROOT, "tests")
_QT_TESTS = os.path.join(_ROOT, "qt_tests")
def _under(path, directory):
return path == directory or path.startswith(directory + os.sep)
def _requested_dirs():
"""Command-line arguments, resolved to absolute paths with any ::nodeid suffix
stripped. Reads sys.argv directly rather than a Config object: no Config exists
yet at conftest-import time, only argv."""
dirs = set()
for arg in sys.argv[1:]:
if not arg or arg.startswith("-"):
continue
candidate = os.path.abspath(arg.split("::", 1)[0])
if _under(candidate, _TESTS):
dirs.add(_TESTS)
elif _under(candidate, _QT_TESTS):
dirs.add(_QT_TESTS)
return dirs
_requested = _requested_dirs()
if _TESTS in _requested and _QT_TESTS in _requested:
sys.exit(
"tests/ and qt_tests/ were both passed to one pytest invocation. They "
"cannot share a process: both install a Qt into aqt.qt, and whichever "
"loads first wins for every internpearls import for the rest of the run. "
"Run them separately, for example:\n"
" python3 -m pytest tests/\n"
" QT_QPA_PLATFORM=offscreen .venv-qt/bin/python -m pytest qt_tests/"
)