This is an automated email from the ASF dual-hosted git repository.

juergbi pushed a commit to branch juerg/update-fixes
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 78159cf19ae92b86b4e32e7ebc4410819653c8b3
Author: Jürg Billeter <[email protected]>
AuthorDate: Fri Jul 26 13:24:50 2024 +0200

    pytest: Set `testpaths` to fix test collection
    
    pytest 8 had breaking changes in test collection, which prevented the
    main test suite from being picked up in combination with our
    `sourcetests_collection_hook`.
---
 setup.cfg                            |  1 +
 src/buildstream/_testing/__init__.py | 19 +++----------------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/setup.cfg b/setup.cfg
index 7be278651..594aabbd7 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -22,6 +22,7 @@ parentdir_prefix = BuildStream-
 
 [tool:pytest]
 addopts = --verbose --basetemp ./tmp --durations=20 --timeout=1800
+testpaths = tests
 norecursedirs = src tests/integration/project tests/plugins/loading 
tests/plugins/sample-plugins integration-cache tmp __pycache__ .eggs
 python_files = tests/*/*.py
 env =
diff --git a/src/buildstream/_testing/__init__.py 
b/src/buildstream/_testing/__init__.py
index a7520c819..7fa3643a2 100644
--- a/src/buildstream/_testing/__init__.py
+++ b/src/buildstream/_testing/__init__.py
@@ -100,23 +100,10 @@ def sourcetests_collection_hook(session):
     """
 
     def should_collect_tests(config):
-        args = config.args
-        rootdir = config.rootdir
-        # When no args are supplied, pytest defaults the arg list to
-        # just include the session's root_dir. We want to collect
+        # When no args are supplied, pytest defaults the arg list to the
+        # value of the `testpaths` configuration option. We want to collect
         # tests as part of the default collection
-        if args == [str(rootdir)]:
-            return True
-
-        # If specific tests are passed, don't collect
-        # everything. Pytest will handle this correctly without
-        # modification.
-        if len(args) > 1 or rootdir not in args:
-            return False
-
-        # If in doubt, collect them, this will be an easier bug to
-        # spot and is less likely to result in bug not being found.
-        return True
+        return config.args_source != pytest.Config.ArgsSource.ARGS
 
     from . import _sourcetests
 

Reply via email to