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

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 4bd5e5bfff Add platform markers for the tests (#38173)
4bd5e5bfff is described below

commit 4bd5e5bfff7c7c31dbd778e768b37fa6984fcd7b
Author: Andrey Anshin <andrey.ans...@taragol.is>
AuthorDate: Sat Mar 16 02:18:30 2024 +0400

    Add platform markers for the tests (#38173)
---
 contributing-docs/testing/unit_tests.rst | 12 ++++++++++++
 tests/conftest.py                        | 23 +++++++++++++++++++++++
 tests/core/test_impersonation_tests.py   |  2 +-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/contributing-docs/testing/unit_tests.rst 
b/contributing-docs/testing/unit_tests.rst
index 53bf3a1210..59082ecf5a 100644
--- a/contributing-docs/testing/unit_tests.rst
+++ b/contributing-docs/testing/unit_tests.rst
@@ -1075,6 +1075,18 @@ This prepares airflow .whl package in the dist folder.
 
      breeze --use-airflow-version wheel --use-packages-from-dist 
--mount-sources skip
 
+Other Settings
+--------------
+
+Skip test on unsupported platform / environment
+...............................................
+
+You can apply the marker ``pytest.mark.platform(name)`` to the specific test 
case, class or module
+for prevent to run on unsupported platform.
+
+- ``linux``: Run test only on linux platform
+- ``breeze``: Run test only inside of Breeze container, it might be useful in 
case of run
+  some potential dangerous things in tests or if it expects to use common 
Breeze things.
 
 Code Coverage
 -------------
diff --git a/tests/conftest.py b/tests/conftest.py
index 7cacce0621..133d78a32b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -338,6 +338,7 @@ def pytest_configure(config):
     config.addinivalue_line("markers", "integration(name): mark test to run 
with named integration")
     config.addinivalue_line("markers", "backend(name): mark test to run with 
named backend")
     config.addinivalue_line("markers", "system(name): mark test to run with 
named system")
+    config.addinivalue_line("markers", "platform(name): mark test to run with 
specific platform/environment")
     config.addinivalue_line("markers", "long_running: mark test that run for a 
long time (many minutes)")
     config.addinivalue_line(
         "markers", "quarantined: mark test that are in quarantine (i.e. flaky, 
need to be isolated and fixed)"
@@ -396,6 +397,26 @@ def skip_if_not_marked_with_backend(selected_backend, 
item):
     )
 
 
+def skip_if_platform_doesnt_match(marker):
+    allowed_platforms = ("linux", "breeze")
+    if not (args := marker.args):
+        pytest.fail(f"No platform specified, expected one of: {', 
'.join(map(repr, allowed_platforms))}")
+    elif not all(a in allowed_platforms for a in args):
+        pytest.fail(
+            f"Allowed platforms {', '.join(map(repr, allowed_platforms))}; "
+            f"but got: {', '.join(map(repr, args))}"
+        )
+    if "linux" in args:
+        if not sys.platform.startswith("linux"):
+            pytest.skip("Test expected to run on Linux platform.")
+    if "breeze" in args:
+        if not os.path.isfile("/.dockerenv") or os.environ.get("BREEZE", 
"").lower() != "true":
+            raise pytest.skip(
+                "Test expected to run into Airflow Breeze container. "
+                "Maybe because it is to dangerous to run it outside."
+            )
+
+
 def skip_if_not_marked_with_system(selected_systems, item):
     for marker in item.iter_markers(name="system"):
         systems_name = marker.args[0]
@@ -539,6 +560,8 @@ def pytest_runtest_setup(item):
         skip_if_not_marked_with_system(selected_systems_list, item)
     else:
         skip_system_test(item)
+    for marker in item.iter_markers(name="platform"):
+        skip_if_platform_doesnt_match(marker)
     for marker in item.iter_markers(name="backend"):
         skip_if_wrong_backend(marker, item)
     selected_backend = item.config.option.backend
diff --git a/tests/core/test_impersonation_tests.py 
b/tests/core/test_impersonation_tests.py
index 3fa2d3b981..b17900820d 100644
--- a/tests/core/test_impersonation_tests.py
+++ b/tests/core/test_impersonation_tests.py
@@ -39,7 +39,7 @@ from tests.test_utils import db
 
 # The entire module into the quarantined mark, this might have unpredictable 
side effects to other tests
 # and should be moved into the isolated environment into the future.
-pytestmark = [pytest.mark.db_test, pytest.mark.quarantined]
+pytestmark = [pytest.mark.platform("breeze"), pytest.mark.db_test, 
pytest.mark.quarantined]
 
 DEV_NULL = "/dev/null"
 TEST_ROOT_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), 
".."))

Reply via email to