Skip to content

Commit 3644077

Browse files
committed
tests: reorder to unpin pytest
Fix: getsentry#3035 Rearrange test items so that forked tests come before normal tests within their respective modules. Swap the last forked test with the last normal test if necessary. Workaround to unpin pytest. See: pytest-dev/pytest#9621, pytest-dev/pytest-forked#67, and specifically: pytest-dev/pytest-forked#67 (comment)
1 parent 5080c76 commit 3644077

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

requirements-devenv.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
-r requirements-linting.txt
22
-r requirements-testing.txt
33
mockupdb # required by `pymongo` tests that are enabled by `pymongo` from linter requirements
4-
pytest<7.0.0 # https://github.com/pytest-dev/pytest/issues/9621; see tox.ini
54
pytest-asyncio

tests/conftest.py

+38
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,41 @@ def __eq__(self, other):
645645

646646
def __ne__(self, other):
647647
return not self.__eq__(other)
648+
649+
650+
def pytest_collection_modifyitems(config, items):
651+
"""
652+
Rearrange test items so that forked tests come before normal tests within their respective modules.
653+
Swap the last forked test with the last normal test if necessary.
654+
655+
Workaround to unpin pytest. See:
656+
https://github.com/pytest-dev/pytest/issues/9621,
657+
https://github.com/pytest-dev/pytest-forked/issues/67, and specifically:
658+
https://github.com/pytest-dev/pytest-forked/issues/67#issuecomment-1964718720
659+
"""
660+
module_states = {}
661+
662+
for idx in range(len(items)):
663+
item = items[idx]
664+
current_module = item.module.__name__
665+
666+
if current_module not in module_states:
667+
module_states[current_module] = {"forked": [], "normal": []}
668+
669+
if "forked" in item.keywords:
670+
module_states[current_module]["forked"].append(idx)
671+
else:
672+
module_states[current_module]["normal"].append(idx)
673+
674+
# Swap the last forked test with the last normal test if necessary
675+
for states in module_states.values():
676+
if states["forked"] and states["normal"]:
677+
last_forked_idx = states["forked"][-1]
678+
last_normal_idx = states["normal"][-1]
679+
680+
if last_forked_idx > last_normal_idx:
681+
# Swap the items
682+
items[last_forked_idx], items[last_normal_idx] = (
683+
items[last_normal_idx],
684+
items[last_forked_idx],
685+
)

tox.ini

-10
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,10 @@ deps =
290290
# === Common ===
291291
py3.8-common: hypothesis
292292
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12,py3.13}-common: pytest-asyncio
293-
# See https://github.com/pytest-dev/pytest/issues/9621
294-
# and https://github.com/pytest-dev/pytest-forked/issues/67
295-
# for justification of the upper bound on pytest
296-
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common: pytest<7.0.0
297-
py3.13-common: pytest
298293

299294
# === Gevent ===
300295
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-gevent: gevent>=22.10.0, <22.11.0
301296
{py3.12}-gevent: gevent
302-
# See https://github.com/pytest-dev/pytest/issues/9621
303-
# and https://github.com/pytest-dev/pytest-forked/issues/67
304-
# for justification of the upper bound on pytest
305-
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: pytest<7.0.0
306297

307298
# === Integrations ===
308299

@@ -372,7 +363,6 @@ deps =
372363
celery-latest: Celery
373364

374365
celery: newrelic
375-
celery: pytest<7
376366
{py3.7}-celery: importlib-metadata<5.0
377367

378368
# Chalice

0 commit comments

Comments
 (0)