Skip to content

Commit

Permalink
Feature/251 pytest 7 (#255)
Browse files Browse the repository at this point in the history
* workaround for CallSpec2 attributes being frozen

* Taking over work from #253 : fixed python 2 builds and added builds for pytest 6 in nox file

* Fixed test with pytest 7

* Removed test config with pytest asyncio pytest 5.x and python 3.8. It seems to be causing issues in gh actions.

* Removed test config with pytest asyncio pytest 5.x and python 3.7. It seems to be causing issues in gh actions.

Co-authored-by: jammer87 <71280324+jammer87@users.noreply.github.com>
Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
  • Loading branch information
3 people committed Feb 8, 2022
1 parent fda5107 commit 52f1256
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
22 changes: 14 additions & 8 deletions noxfile.py
Expand Up @@ -22,9 +22,11 @@
# (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": ""}},
(PY39, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
# python 3.8
(PY38, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
(PY38, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
(PY38, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6", "pytest-asyncio": DONT_INSTALL}},
(PY38, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
(PY38, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
# python 2.7
(PY27, "pytest2.x"): {"coverage": False, "pkg_specs": {"pip": ">10", "pytest": "<3", "pytest-asyncio": DONT_INSTALL}},
Expand All @@ -35,16 +37,17 @@
(PY35, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">10", "pytest": "<4", "pytest-asyncio": DONT_INSTALL}},
(PY35, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">10", "pytest": "<5", "pytest-asyncio": DONT_INSTALL}},
(PY35, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">10", "pytest": "<6"}},
(PY35, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">10", "pytest": ""}},
# python 3.6
(PY36, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
(PY36, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
(PY36, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
(PY36, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
(PY36, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
# python 3.7
(PY37, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
(PY37, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
(PY37, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
(PY37, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6", "pytest-asyncio": DONT_INSTALL}},
(PY37, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
# IMPORTANT: this should be last so that the folder docs/reports is not deleted afterwards
(PY37, "pytest-latest"): {"coverage": True, "pkg_specs": {"pip": ">19", "pytest": ""}}
}
Expand Down Expand Up @@ -123,17 +126,20 @@ def tests(session: PowerSession, coverage, pkg_specs):
# Fail if the assumed python version is not the actual one
session.run2("python ci_tools/check_python_version.py %s" % session.python)

# install self so that it is recognized by pytest
session.run2("pip install -e . --no-deps")

# check that it can be imported even from a different folder
session.run2(['python', '-c', '"import os; os.chdir(\'./docs/\'); import %s"' % pkg_name])
# session.run2(['python', '-c', '"import os; os.chdir(\'./docs/\'); import %s"' % pkg_name])

# finally run all tests
if not coverage:
# install self
session.run2("pip install . --no-deps")

# simple: pytest only
session.run2("python -m pytest --cache-clear -v tests/")
else:
# install self in dev mode so that coverage works
session.run2("pip install -e . --no-deps")

# coverage + junit html reports + badge generation
session.install_reqs(phase="coverage",
phase_reqs=["coverage", "pytest-html", "genbadge[tests,coverage]"],
Expand Down Expand Up @@ -162,7 +168,7 @@ def flake8(session: PowerSession):

session.install("-r", str(Folders.ci_tools / "flake8-requirements.txt"))
session.install("genbadge[flake8]")
session.run2("pip install -e .[flake8]")
session.run2("pip install .")

rm_folder(Folders.flake8_reports)
Folders.flake8_reports.mkdir(parents=True, exist_ok=True)
Expand Down
14 changes: 13 additions & 1 deletion src/pytest_cases/common_others.py
Expand Up @@ -15,7 +15,7 @@
except ImportError:
pass

from .common_mini_six import string_types, PY3
from .common_mini_six import string_types, PY3, PY34


def get_code_first_line(f):
Expand Down Expand Up @@ -573,3 +573,15 @@ def make_identifier(name # type: str
if re.match("^(?=\\d)", new_name):
new_name = "_" + new_name
return new_name


if PY34:
def replace_list_contents(the_list, new_contents):
"""Replaces the contents of a list"""
the_list.clear()
the_list.extend(new_contents)
else:
def replace_list_contents(the_list, new_contents):
"""Replaces the contents of a list"""
del the_list[:]
the_list.extend(new_contents)
6 changes: 3 additions & 3 deletions src/pytest_cases/fixture_parametrize_plus.py
Expand Up @@ -26,7 +26,7 @@
from makefun import with_signature, remove_signature_parameters, add_signature_parameters, wraps

from .common_mini_six import string_types
from .common_others import AUTO, robust_isinstance
from .common_others import AUTO, robust_isinstance, replace_list_contents
from .common_pytest_marks import has_pytest_param, get_param_argnames_as_list
from .common_pytest_lazy_values import is_lazy_value, get_lazy_args
from .common_pytest import get_fixture_name, remove_duplicates, mini_idvalset, is_marked_parameter_value, \
Expand Down Expand Up @@ -553,11 +553,11 @@ def get_alternative_id(self):
if has_pytest_param:
def remove_empty_ids(callspec):
# used by plugin.py to remove the EMPTY_ID from the callspecs
callspec._idlist = [c for c in callspec._idlist if not c.startswith(EMPTY_ID)]
replace_list_contents(callspec._idlist, [c for c in callspec._idlist if not c.startswith(EMPTY_ID)])
else:
def remove_empty_ids(callspec):
# used by plugin.py to remove the EMPTY_ID from the callspecs
callspec._idlist = [c for c in callspec._idlist if not c.endswith(EMPTY_ID)]
replace_list_contents(callspec._idlist, [c for c in callspec._idlist if not c.endswith(EMPTY_ID)])


# elif PYTEST421_OR_GREATER:
Expand Down
Expand Up @@ -77,14 +77,15 @@ def test_three(myfix2, myfix3):
print(myfix2)


def test_synthesis(module_results_dct):
def test_synthesis2(module_results_dct):
"""Use pytest-harvest to check that the list of executed tests is correct """

assert list(module_results_dct) == ['test_one[one-one]',
'test_one[one-two]',
'test_one[two-one]',
'test_one[two-two]',
'test_synthesis',
'test_two[1-2-!0!]',
'test_two[p_a-!0!]',
'test_three[1-2-!0!-a]',
'test_three[p_a-!0!-a]']
'test_three[p_a-!0!-a]']

0 comments on commit 52f1256

Please sign in to comment.