You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/12/15 19:59:27 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #28378: Migrate remaining Core tests to `pytest`

uranusjr commented on code in PR #28378:
URL: https://github.com/apache/airflow/pull/28378#discussion_r1050081585


##########
tests/core/test_impersonation_tests.py:
##########
@@ -47,55 +46,33 @@
 logger = logging.getLogger(__name__)
 
 
-def mock_custom_module_path(path: str):
-    """
-    This decorator adds a path to sys.path to simulate running the current script with
-    the :envvar:`PYTHONPATH` environment variable set and sets the environment variable
-    :envvar:`PYTHONPATH` to change the module load directory for child scripts.
-    """
-
-    def wrapper(func):
-        @functools.wraps(func)
-        def decorator(*args, **kwargs):
-            copy_sys_path = deepcopy(sys.path)
-            sys.path.append(path)
-            try:
-                with unittest.mock.patch.dict("os.environ", {"PYTHONPATH": path}):
-                    return func(*args, **kwargs)
-            finally:
-                sys.path = copy_sys_path
-
-        return decorator
-
-    return wrapper
+@pytest.fixture
+def check_original_docker_image():
+    if not os.path.isfile("/.dockerenv") or os.environ.get("PYTHON_BASE_IMAGE") is None:
+        raise pytest.skip(
+            "Adding/removing a user as part of a test is very bad for host os "
+            "(especially if the user already existed to begin with on the OS), "
+            "therefore we check if we run inside a the official docker container "
+            "and only allow to run the test there. This is done by checking /.dockerenv file "
+            "(always present inside container) and checking for PYTHON_BASE_IMAGE variable."
+        )
+    yield

Review Comment:
   ```suggestion
   ```
   
   Not needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org