Skip to content

Commit f8b62b8

Browse files
committed
fix(test): tighten container-test detection in run-unit-tests
The container-vs-fast heuristic used plain `'podman' in content` and `'testcontainers' in content` substring matches, which also fired on comments, docstrings, and on plugin names that happen to contain the word `podman`. As a result, `apache-httpd-status`, `deb-updates`, `needs-restarting`, `rpm-updates`, `podman-info`, and `podman-stats` were silently skipped by `tools/run-unit-tests --no-container` and therefore by the full `tox` matrix. Match on precise signatures instead: `import testcontainers`, `from testcontainers`, `lib.lftest.run_container(`, `DockerImage(`, and `DockerContainer(`. Those strings only appear in real container drivers, not in incidental mentions of the word.
1 parent e055a53 commit f8b62b8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tools/run-unit-tests

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,36 @@ import sys
4747
SKIP_PLUGINS = {'example'}
4848

4949

50+
# Signatures that identify a real container-driven unit test. These must
51+
# be precise substring matches: a plain keyword like `podman` would also
52+
# fire on comments, docstrings, or on plugins whose name happens to
53+
# contain `podman` (e.g. `podman-info`, `podman-stats`), which used to
54+
# cause fixture-based tests to be silently skipped by the multi-Python
55+
# matrix.
56+
CONTAINER_TEST_SIGNATURES = (
57+
'import testcontainers',
58+
'from testcontainers',
59+
'lib.lftest.run_container(',
60+
'DockerContainer(',
61+
'DockerImage(',
62+
)
63+
64+
5065
def is_container_test(check_plugins, plugin):
5166
"""Return True if the plugin's unit test actually drives a container runtime.
5267
5368
We look at the `run` file's content rather than the presence of a
5469
`containerfiles/` subdirectory: a plugin may keep containerfiles around
5570
for a future testcontainers migration while its `run` file is already
56-
fixture-based and fast. The run file counts as a container test when
57-
it references `podman` as a subprocess target or imports `testcontainers`.
71+
fixture-based and fast.
5872
"""
5973
run_file = os.path.join(check_plugins, plugin, 'unit-test', 'run')
6074
try:
6175
with open(run_file, encoding='utf-8') as f:
6276
content = f.read()
6377
except OSError:
6478
return False
65-
return 'podman' in content or 'testcontainers' in content
79+
return any(sig in content for sig in CONTAINER_TEST_SIGNATURES)
6680

6781

6882
def main():

0 commit comments

Comments
 (0)