[elbe-devel] [PATCH 03/10] elbepack: pytest: mark test_xml as slow

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Mar 11 18:02:56 CET 2024


These tests are very slow and expensive.
Don't run them by default in pytest, the same it was done with the
custom test runner.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 conftest.py                | 21 +++++++++++++++++++++
 elbepack/tests/test_xml.py |  4 ++++
 2 files changed, 25 insertions(+)

diff --git a/conftest.py b/conftest.py
index 91a531725f76..d29b2c04182c 100644
--- a/conftest.py
+++ b/conftest.py
@@ -7,3 +7,24 @@ import elbepack.directories
 def pytest_sessionstart(session):
     elbepack.directories.elbe_exe = os.path.join(os.path.dirname(__file__), 'elbe')
     elbepack.directories.elbe_dir = os.path.dirname(__file__)
+
+
+# https://stackoverflow.com/a/61193490
+def pytest_addoption(parser):
+    parser.addoption(
+        "--runslow", action="store_true", default=False, help="run slow tests"
+    )
+
+
+def pytest_configure(config):
+    config.addinivalue_line("markers", "slow: mark test as slow to run")
+
+
+def pytest_collection_modifyitems(config, items):
+    if config.getoption("--runslow"):
+        # --runslow given in cli: do not skip slow tests
+        return
+    skip_slow = pytest.mark.skip(reason="need --runslow option to run")
+    for item in items:
+        if "slow" in item.keywords:
+            item.add_marker(skip_slow)
diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index 65f83d843110..000add833b5e 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -10,9 +10,12 @@ import unittest
 from elbepack.commands.test import ElbeTestCase, ElbeTestLevel, system
 from elbepack.directories import elbe_dir, elbe_exe
 
+import pytest
+
 
 @unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.INITVM,
                  'Test level not set to INITVM')
+ at pytest.mark.slow
 class TestSimpleXML(ElbeTestCase):
 
     def test_simple_build(self):
@@ -52,6 +55,7 @@ class TestSimpleXML(ElbeTestCase):
 
 @unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.INITVM,
                  'Test level not set to INITVM')
+ at pytest.mark.slow
 class TestPbuilder(ElbeTestCase):
 
     def test_pbuilder_build(self):

-- 
2.44.0



More information about the elbe-devel mailing list