|
4 | 4 | """ |
5 | 5 |
|
6 | 6 | import sys |
7 | | -import tempfile |
8 | 7 | from types import ModuleType |
9 | 8 | from typing import Any |
10 | 9 |
|
11 | | - |
12 | | -def getrootdir(config: Any = None) -> str: |
13 | | - """Compatibility function for pytest_xprocess.getrootdir""" |
14 | | - return tempfile.gettempdir() |
15 | | - |
16 | | - |
17 | | -# Try to import from the new xprocess structure |
| 10 | +# Create the pytest_xprocess module by directly importing from xprocess.pytest_xprocess |
18 | 11 | try: |
19 | | - import xprocess |
20 | | - |
21 | | - # Create a mock pytest_xprocess module that maps to xprocess functionality |
22 | | - if "pytest_xprocess" not in sys.modules: |
23 | | - mock_module = ModuleType("pytest_xprocess") |
24 | | - |
25 | | - # Map the getrootdir function |
26 | | - if hasattr(xprocess, "getrootdir"): |
27 | | - mock_module.getrootdir = xprocess.getrootdir # type: ignore |
28 | | - else: |
29 | | - mock_module.getrootdir = getrootdir # type: ignore |
30 | | - |
31 | | - # Try to find other attributes that might be needed |
32 | | - if hasattr(xprocess, "__version__"): |
33 | | - mock_module.__version__ = xprocess.__version__ # type: ignore |
34 | | - else: |
35 | | - mock_module.__version__ = "1.0.0" # type: ignore |
36 | | - |
37 | | - mock_module.__file__ = __file__ |
38 | | - sys.modules["pytest_xprocess"] = mock_module |
| 12 | + # Import the entire module directly |
| 13 | + import xprocess.pytest_xprocess as pytest_xprocess_module # isort:skip |
| 14 | + from xprocess.pytest_xprocess import * # noqa: F401, F403, isort:skip |
| 15 | + # Add it to sys.modules as pytest_xprocess |
| 16 | + sys.modules["pytest_xprocess"] = pytest_xprocess_module |
39 | 17 |
|
40 | 18 | except ImportError: |
41 | | - # If xprocess isn't available, create a full mock module |
42 | | - if "pytest_xprocess" not in sys.modules: |
43 | | - mock_module = ModuleType("pytest_xprocess") |
44 | | - mock_module.getrootdir = getrootdir # type: ignore |
45 | | - mock_module.__version__ = "1.0.0" # type: ignore |
46 | | - mock_module.__file__ = __file__ |
47 | | - sys.modules["pytest_xprocess"] = mock_module |
| 19 | + # Fallback if xprocess.pytest_xprocess isn't available |
| 20 | + import tempfile |
| 21 | + |
| 22 | + def getrootdir(config: Any = None) -> str: |
| 23 | + """Compatibility function for pytest_xprocess.getrootdir""" |
| 24 | + return tempfile.gettempdir() |
| 25 | + |
| 26 | + # Create a minimal mock module |
| 27 | + mock_module = ModuleType("pytest_xprocess") |
| 28 | + mock_module.getrootdir = getrootdir # type: ignore |
| 29 | + mock_module.__version__ = "1.0.0" # type: ignore |
| 30 | + mock_module.__file__ = __file__ |
| 31 | + sys.modules["pytest_xprocess"] = mock_module |
0 commit comments