]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test/py: Allow tests to be marked single-threaded only
authorSimon Glass <sjg@chromium.org>
Sat, 6 Aug 2022 23:51:47 +0000 (17:51 -0600)
committerTom Rini <trini@konsulko.com>
Mon, 12 Sep 2022 22:06:36 +0000 (18:06 -0400)
Add a new 'singlethread' marker to allow tests to be skipped when running
in parallel.

Signed-off-by: Simon Glass <sjg@chromium.org>
test/py/conftest.py
test/py/pytest.ini

index 2ba34479e035eab47c95316799871b6cd163001c..dbe1acd9e3727f012e86747543bb8c84e662ba12 100644 (file)
@@ -521,6 +521,22 @@ def setup_requiredtool(item):
         if not tool_is_in_path(tool):
             pytest.skip('tool "%s" not in $PATH' % tool)
 
+def setup_singlethread(item):
+    """Process any 'singlethread' marker for a test.
+
+    Skip this test if running in parallel.
+
+    Args:
+        item: The pytest test item.
+
+    Returns:
+        Nothing.
+    """
+    for single in item.iter_markers('singlethread'):
+        worker_id = os.environ.get("PYTEST_XDIST_WORKER")
+        if worker_id and worker_id != 'master':
+            pytest.skip('must run single-threaded')
+
 def start_test_section(item):
     anchors[item.name] = log.start_section(item.name)
 
@@ -541,6 +557,7 @@ def pytest_runtest_setup(item):
     setup_boardspec(item)
     setup_buildconfigspec(item)
     setup_requiredtool(item)
+    setup_singlethread(item)
 
 def pytest_runtest_protocol(item, nextitem):
     """pytest hook: Called to execute a test.
index e93d010f1fa2e3e652f3d0fb48fa8300b0ee134e..26d83f83e0036b548c744e5c32e7aad78e144bb6 100644 (file)
@@ -11,3 +11,4 @@ markers =
     notbuildconfigspec: U-Boot: Describes required disabled Kconfig options.
     requiredtool: U-Boot: Required host tools for a test.
     slow: U-Boot: Specific test will run slowly.
+    singlethread: Cannot run in parallel