22
22
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
# SOFTWARE.
24
24
25
- """Pytest Fixtures for supporting the PARALLEL_MONO_SCOPE Test Distribution Mode .
25
+ """Pytest Fixtures for supporting users of isoscope scheduling .
26
26
27
- NOTE: These fixtures are NOT compatible with any other Test Distribution Modes .
27
+ NOTE: These fixtures are NOT compatible with any other xdist schedulers .
28
28
29
29
NOTE: DO NOT IMPORT this module. It needs to be loaded via pytest's
30
30
`conftest.pytest_plugins` mechanism. Pytest doc discourages importing fixtures
46
46
import filelock
47
47
import pytest
48
48
49
- from utils . common . parallel_mono_scope_utils import (
50
- ParallelMonoScopeFixture ,
49
+ from xdist . iso_scheduling_utils import (
50
+ IsoSchedulingFixture ,
51
51
DistributedSetupCoordinator ,
52
52
DistributedSetupContext ,
53
53
DistributedTeardownContext ,
63
63
64
64
65
65
@pytest .fixture (scope = 'session' )
66
- def parallel_mono_scope (
66
+ def iso_scheduling (
67
67
tmp_path_factory : pytest .TempPathFactory ,
68
68
testrun_uid : str ,
69
69
worker_id : str
70
- ) -> ParallelMonoScopeFixture :
70
+ ) -> IsoSchedulingFixture :
71
71
"""A session-scoped pytest fixture for coordinating setup/teardown of test
72
- scope/class which is executing in the parallel_mono_scope Test Distribution
73
- Mode.
72
+ scope/class which is executing under isoscope scheduling.
74
73
75
74
NOTE: Each XDist remote worker is running its own Pytest Session.
76
75
@@ -82,24 +81,23 @@ def parallel_mono_scope(
82
81
import pytest
83
82
84
83
if TYPE_CHECKING:
85
- from utils.common.parallel_mono_scope_utils import (
86
- ParallelMonoScopeFixture ,
84
+ from xdist.iso_scheduling_utils import (
85
+ IsoSchedulingFixture ,
87
86
DistributedSetupContext,
88
87
DistributedTeardownContext
89
88
)
90
89
91
- @pytest.mark.parallel_mono_scope
92
- class TestDeng12345ParallelMonoScope:
90
+ class TestSomething:
93
91
94
92
@classmethod
95
93
@pytest.fixture(scope='class', autouse=True)
96
94
def distributed_setup_and_teardown(
97
95
cls,
98
- parallel_mono_scope: ParallelMonoScopeFixture :
96
+ iso_scheduling: IsoSchedulingFixture :
99
97
request: pytest.FixtureRequest):
100
98
101
99
# Distributed Setup and Teardown
102
- with parallel_mono_scope .coordinate_setup_teardown(
100
+ with iso_scheduling .coordinate_setup_teardown(
103
101
setup_request=request) as coordinator:
104
102
# Distributed Setup
105
103
coordinator.maybe_call_setup(cls.patch_system_under_test)
@@ -126,12 +124,13 @@ def revert_system_under_test(
126
124
# Fetch state from `teardown_context.client_dir` and revert
127
125
# changes made by `patch_system_under_test()`.
128
126
129
- perms, tc_ids = generate_tests(
130
- os.path.realpath(__file__),
131
- TestDistributionModeEnum.PARALLEL_MONO_SCOPE)
127
+ def test_case1(self)
128
+ ...
129
+
130
+ def test_case2(self)
131
+ ...
132
132
133
- @pytest.mark.parametrize('test_data', perms, ids=tc_ids)
134
- def test_case(self, test_data: dict[str, dict])
133
+ def test_case3(self)
135
134
...
136
135
```
137
136
@@ -146,17 +145,17 @@ def test_case(self, test_data: dict[str, dict])
146
145
yields an instance of `DistributedSetupCoordinator` for the current
147
146
Pytest Session.
148
147
"""
149
- return _ParallelMonoScopeFixtureImpl (tmp_path_factory = tmp_path_factory ,
150
- testrun_uid = testrun_uid ,
151
- worker_id = worker_id )
148
+ return _IsoSchedulingFixtureImpl (tmp_path_factory = tmp_path_factory ,
149
+ testrun_uid = testrun_uid ,
150
+ worker_id = worker_id )
152
151
153
152
154
- class _ParallelMonoScopeFixtureImpl ( ParallelMonoScopeFixture ):
153
+ class _IsoSchedulingFixtureImpl ( IsoSchedulingFixture ):
155
154
"""Context manager yielding a new instance of the implementation of the
156
155
`DistributedSetupCoordinator` interface.
157
156
158
- An instance of _ParallelMonoScopeFixtureImpl is returned by our pytest
159
- fixture `parallel_mono_scope `.
157
+ An instance of _IsoSchedulingFixtureImpl is returned by our pytest
158
+ fixture `iso_scheduling `.
160
159
"""
161
160
# pylint: disable=too-few-public-methods
162
161
@@ -206,11 +205,11 @@ def coordinate_setup_teardown(
206
205
207
206
208
207
class _DistributedSetupCoordinatorImpl (DistributedSetupCoordinator ):
209
- """Distributed scope/class setup/teardown coordination for the
210
- `parallel_mono_scope` Test Distribution Mode .
208
+ """Distributed scope/class setup/teardown coordination for isoscope
209
+ scheduling .
211
210
212
211
NOTE: do not instantiate this class directly. Use the
213
- `parallel_mono_scope ` fixture instead!
212
+ `iso_scheduling ` fixture instead!
214
213
215
214
"""
216
215
_DISTRIBUTED_SETUP_ROOT_DIR_LINK_NAME = 'distributed_setup'
@@ -257,7 +256,7 @@ def maybe_call_setup(
257
256
Process-safe.
258
257
259
258
Call `maybe_call_setup` from the pytest setup-teardown fixture of your
260
- `PARALLEL_MONO_SCOPE` test (typically test class) if it needs to
259
+ isoscope-scheduled test (typically test class) if it needs to
261
260
initialize a resource which is common to all of its test cases which may
262
261
be executing in different XDist worker processes (such as a subnet in
263
262
`subnet.xml`).
@@ -272,8 +271,7 @@ def maybe_call_setup(
272
271
:return: An instance of `DistributedSetupContext` which MUST be passed
273
272
in the corresponding call to `maybe_call_teardown`.
274
273
275
- :raise parallel_mono_scope.CoordinationTimeoutError: If attempt to
276
- acquire the lock times out.
274
+ :raise CoordinationTimeoutError: If attempt to acquire the lock times out.
277
275
"""
278
276
# `maybe_call_setup()` may be called only once per instance of
279
277
# `_SetupCoordinator`
@@ -307,7 +305,7 @@ def maybe_call_teardown(
307
305
tests for your test scope. Process-safe.
308
306
309
307
Call `maybe_call_teardown` from the pytest setup-teardown fixture of
310
- your `PARALLEL_MONO_SCOPE` test (typically test class) if it needs to
308
+ your isoscope-scheduled test (typically test class) if it needs to
311
309
initialize a resource which is common to all of its test cases which may
312
310
be executing in different XDist worker processes (such as a subnet in
313
311
`subnet.xml`).
@@ -320,8 +318,7 @@ def maybe_call_teardown(
320
318
invoked.
321
319
:param timeout: Lock acquisition timeout in seconds
322
320
323
- :raise parallel_mono_scope.CoordinationTimeoutError: If attempt to
324
- acquire the lock times out.
321
+ :raise CoordinationTimeoutError: If attempt to acquire the lock times out.
325
322
"""
326
323
# Make sure `maybe_call_setup()` was already called on this instance
327
324
# of `_SetupCoordinator`
@@ -359,8 +356,7 @@ def wrapper(*args, **kwargs):
359
356
360
357
class _DistributedSetupCoordinationImpl :
361
358
"""Low-level implementation of Context Managers for Coordinating
362
- Distributed Setup and Teardown for the `parallel_mono_scope`
363
- Test Distribution Mode.
359
+ Distributed Setup and Teardown for users of isoscope scheduling.
364
360
"""
365
361
_ROOT_STATE_FILE_NAME = 'root_state.json'
366
362
_ROOT_LOCK_FILE_NAME = 'lock'
@@ -426,7 +422,7 @@ def acquire_distributed_setup(
426
422
timeout : float
427
423
) -> Generator [DistributedSetupContext , None , None ]:
428
424
"""Low-level implementation of Context Manager for Coordinating
429
- Distributed Setup for the `parallel_mono_scope` Test Distribution Mode .
425
+ Distributed Setup for isoscope scheduling .
430
426
431
427
:param root_context_dir: Scope/class-specific root directory for
432
428
saving this context manager's state. This directory is common to
@@ -436,8 +432,7 @@ def acquire_distributed_setup(
436
432
directly by the calling setup-teardown fixture.
437
433
:param timeout: Lock acquisition timeout in seconds
438
434
439
- :raise parallel_mono_scope.CoordinationTimeoutError: If attempt to
440
- acquire the lock times out.
435
+ :raise CoordinationTimeoutError: If attempt to acquire the lock times out.
441
436
"""
442
437
#
443
438
# Before control passes to the managed code block
@@ -502,16 +497,14 @@ def acquire_distributed_teardown(
502
497
timeout : float
503
498
) -> Generator [DistributedTeardownContext , None , None ]:
504
499
"""Low-level implementation of Context Manager for Coordinating
505
- Distributed Teardown for the `parallel_mono_scope` Test Distribution
506
- Mode.
500
+ Distributed Teardown for the isoscope scheduling.
507
501
508
502
:param setup_context: The instance of `DistributedSetupContext` that was
509
503
yielded by the corresponding use of the
510
504
`_distributed_setup_permission` context manager.
511
505
:param timeout: Lock acquisition timeout in seconds
512
506
513
- :raise parallel_mono_scope.CoordinationTimeoutError: If attempt to
514
- acquire the lock times out.
507
+ :raise CoordinationTimeoutError: If attempt to acquire the lock times out.
515
508
"""
516
509
#
517
510
# Before control passes to the managed code block
0 commit comments