Skip to content

Commit 2575da7

Browse files
authored
untangle entangled tests (quantumlib#5892)
- Avoid clashing test mocks of QuantumEngineServiceClient by limiting mocking to the relevant test module. - Enable test reordering by pytest-randomly. Fixes quantumlib#5870.
1 parent 4ce0363 commit 2575da7

File tree

7 files changed

+6
-10
lines changed

7 files changed

+6
-10
lines changed

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ jobs:
135135
- name: Install dependencies
136136
run: pip install -r dev_tools/requirements/isolated-base.env.txt
137137
- name: Test each module in isolation
138-
# TODO(#5870) - remove --randomly-dont-reorganize after fixing order-related test failures
139-
run: pytest --randomly-dont-reorganize -n auto -m slow dev_tools/packaging/isolated_packages_test.py
138+
run: pytest -n auto -m slow dev_tools/packaging/isolated_packages_test.py
140139
pytest:
141140
name: Pytest Ubuntu
142141
strategy:

check/pytest

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
1616
cd "$(git rev-parse --show-toplevel)"
1717

1818
PYTEST_ARGS=()
19-
# TODO(#5870) - remove this after fixing order-related test failures
20-
PYTEST_ARGS+=("--randomly-dont-reorganize")
2119

2220
PARALLEL=""
2321
for arg in "$@"; do

cirq-google/cirq_google/engine/engine_job_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from cirq_google.engine.test_utils import uses_async_mock
2929

3030

31-
@pytest.fixture(scope='session', autouse=True)
31+
@pytest.fixture(scope='module', autouse=True)
3232
def mock_grpc_client():
3333
with mock.patch(
3434
'cirq_google.engine.engine_client.quantum.QuantumEngineServiceClient'

cirq-google/cirq_google/engine/engine_processor_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _to_timestamp(json_string):
207207
)
208208

209209

210-
@pytest.fixture(scope='session', autouse=True)
210+
@pytest.fixture(scope='module', autouse=True)
211211
def mock_grpc_client():
212212
with mock.patch(
213213
'cirq_google.engine.engine_client.quantum.QuantumEngineServiceClient'

cirq-google/cirq_google/engine/engine_program_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def test_get_batch_size(get_program_async):
479479
_ = program.batch_size()
480480

481481

482-
@pytest.fixture(scope='session', autouse=True)
482+
@pytest.fixture(scope='module', autouse=True)
483483
def mock_grpc_client():
484484
with mock.patch(
485485
'cirq_google.engine.engine_client.quantum.QuantumEngineServiceClient'

cirq-google/cirq_google/engine/engine_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_make_random_id():
276276
assert random_id != random_id2
277277

278278

279-
@pytest.fixture(scope='session', autouse=True)
279+
@pytest.fixture(scope='module', autouse=True)
280280
def mock_grpc_client_async():
281281
with mock.patch(
282282
'cirq_google.engine.engine_client.quantum.QuantumEngineServiceAsyncClient', autospec=True

dev_tools/packaging/isolated_packages_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def test_isolated_packages(cloned_env, module):
4848
)
4949
assert result.returncode == 0, f"Failed to install {module.name}:\n{result.stderr}"
5050

51-
# TODO(#5870) - remove --randomly-dont-reorganize after fixing order-related test failures
5251
result = shell_tools.run(
53-
f"{env}/bin/pytest --randomly-dont-reorganize ./{module.root} --ignore ./cirq-core/cirq/contrib".split(),
52+
f"{env}/bin/pytest ./{module.root} --ignore ./cirq-core/cirq/contrib".split(),
5453
capture_output=True,
5554
check=False,
5655
)

0 commit comments

Comments
 (0)