Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/251 pytest 7 #255

Merged
merged 5 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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]']