Skip to content

Commit

Permalink
Fixes part of #321 by solving issues related to the new fixture event…
Browse files Browse the repository at this point in the history
…_loop_policy in our tests
  • Loading branch information
Sylvain MARIE committed Jan 11, 2024
1 parent b8b67fd commit b6fb7f6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ci_tools/nox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ def _f_wrapper(**kwargs):
except KeyError:
# Skip this session, it is a dummy one
nox_logger.warning(
"Skipping configuration, this is not supported in python version %r" % session.python
"Skipping configuration, %r is not meant to be executed in this now session for python version %r" %
(grid_param if has_parameter else "this", session.python)
)
return

Expand Down
4 changes: 3 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog

### 3.8.2 (in progress) - bugfixes and compliance with pytest 8
### 3.8.2 - bugfixes and compliance with pytest 8

- Fixed `import file mismatch` with pytest 8 when executing tests. Improved
error message in case of cases loading error.
Fixes [#323](https://github.com/smarie/python-pytest-cases/issues/323).
Fixes part of
[#321](https://github.com/smarie/python-pytest-cases/issues/321).
- Corrected API documentation (and comments) for the second file-name
pattern for `AUTO`-cases lookup (`cases_<name>.py` instead of
`case_<name>.py`). PR [#320](https://github.com/smarie/python-pytest-cases/pull/320)
Expand Down
4 changes: 4 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@


ENVS = {
# python 3.12
(PY312, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
(PY312, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
# python 3.11
(PY311, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
# python 3.10
(PY310, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
# python 3.9 - put first to detect easy issues faster.
(PY39, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
Expand Down
15 changes: 14 additions & 1 deletion tests/pytest_extension/doc/test_doc_fixture_graph_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
# + All contributors to <https://github.com/smarie/python-pytest-cases>
#
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE>
from packaging.version import Version

import pytest
from pytest_cases import fixture, parametrize, fixture_union, fixture_ref


PYTEST_VERSION = Version(pytest.__version__)
PYTEST7_OR_GREATER = PYTEST_VERSION >= Version('7.0.0')


@fixture(autouse=True)
@parametrize(ie=[-1, 1])
def e(ie):
Expand Down Expand Up @@ -58,7 +65,7 @@ def test_1(u, request):
def test_closure():
# make sure that the closure tree looks good
global super_closure
assert str(super_closure) == """SuperClosure with 3 alternative closures:
ref_str = """SuperClosure with 3 alternative closures:
- ['environment', 'e', 'request', 'u', 'a', 'c', 'd'] (filters: u=u[0]=a)
- ['environment', 'e', 'request', 'u', 'b', 'b_ub', 'a', 'c', 'd'] (filters: u=u[1]=b, b_ub=b_ub[0]=a)
- ['environment', 'e', 'request', 'u', 'b', 'b_ub', 'c'] (filters: u=u[1]=b, b_ub=b_ub[1]=c)
Expand All @@ -71,3 +78,9 @@ def test_closure():
- (a,c,d)
- (c)
"""

if PYTEST7_OR_GREATER:
ref_str = ref_str.replace("(environment,", "(event_loop_policy,environment,")
ref_str = ref_str.replace("['environment',", "['event_loop_policy', 'environment',")

assert str(super_closure) == ref_str
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import warnings

from copy import copy
from packaging.version import Version

import pytest

from pytest_cases.plugin import SuperClosure
from pytest_cases import fixture, fixture_union


PYTEST_VERSION = Version(pytest.__version__)
PYTEST7_OR_GREATER = PYTEST_VERSION >= Version('7.0.0')


@fixture(autouse=True)
def a():
return
Expand Down Expand Up @@ -42,8 +47,10 @@ def test_super_closure_edits2():
global super_closure
assert isinstance(super_closure, SuperClosure)
super_closure = copy(super_closure)
assert len(super_closure) == 4
reflist = ['environment', 'a', 'request', 'b']
if PYTEST7_OR_GREATER:
reflist = ['event_loop_policy'] + reflist
assert len(super_closure) == len(reflist)
assert list(super_closure) == reflist
assert super_closure[:] == reflist[:]
assert super_closure[1] == reflist[1]
Expand All @@ -54,9 +61,9 @@ def test_super_closure_edits2():
super_closure[1] = reflist[1]
super_closure[::2] = reflist[::2]
with pytest.warns(UserWarning):
super_closure[2:] = ['b', 'request']
super_closure[2+PYTEST7_OR_GREATER:] = ['b', 'request']
# the above operation is allowed but does nothing and a warning is issued.
assert super_closure[2:] == ['request', 'b']
assert super_closure[2+PYTEST7_OR_GREATER:] == ['request', 'b']

# removing now works
super_closure.remove('request')
Expand All @@ -69,6 +76,10 @@ def test_super_closure_edits2():
# we can remove the 'environment' one
del super_closure[0]
del reflist[0]
if PYTEST7_OR_GREATER:
# remove event_loop_policy and environment
del super_closure[0]
del reflist[0]
assert list(super_closure) == reflist

# now supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
# + All contributors to <https://github.com/smarie/python-pytest-cases>
#
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE>
from packaging.version import Version

import pytest

from pytest_cases.plugin import SuperClosure
from pytest_cases import param_fixture, fixture_union


PYTEST_VERSION = Version(pytest.__version__)
PYTEST7_OR_GREATER = PYTEST_VERSION >= Version('7.0.0')


# basic parametrized fixtures
a = param_fixture('a', ['x', 'y'])
b = param_fixture('b', [1, 2])
Expand Down Expand Up @@ -48,7 +57,7 @@ def test_super_closure():

# make sure that the closure tree looks good
assert isinstance(super_closure, SuperClosure)
assert str(super_closure) == """SuperClosure with 4 alternative closures:
ref_str = """SuperClosure with 4 alternative closures:
- ['environment', 'c', 'a', 'request', 'd', 'b'] (filters: c=c[0]=a, d=d[0]=b)
- ['environment', 'c', 'a', 'request', 'd'] (filters: c=c[0]=a, d=d[1]=a)
- ['environment', 'c', 'b', 'request', 'a', 'd'] (filters: c=c[1]=b, d=d[0]=b)
Expand All @@ -64,3 +73,9 @@ def test_super_closure():
- ()
- ()
"""

if PYTEST7_OR_GREATER:
ref_str = ref_str.replace("(environment,", "(event_loop_policy,environment,")
ref_str = ref_str.replace("['environment',", "['event_loop_policy', 'environment',")

assert str(super_closure) == ref_str

0 comments on commit b6fb7f6

Please sign in to comment.