Skip to content

Commit

Permalink
Taking over work from #253 : fixed python 2 builds and added builds f…
Browse files Browse the repository at this point in the history
…or pytest 6 in nox file
  • Loading branch information
Sylvain MARIE committed Feb 8, 2022
1 parent 7690fe6 commit a511c3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
18 changes: 12 additions & 6 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, "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, "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)
12 changes: 3 additions & 9 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 @@ -550,20 +550,14 @@ def get_alternative_id(self):
EMPTY_ID = "<pytest_cases_empty_id>"


def _replace_list_contents(the_list, new_contents):
"""Replaces the contents of a list"""
the_list.clear()
the_list.extend(new_contents)


if has_pytest_param:
def remove_empty_ids(callspec):
# used by plugin.py to remove the EMPTY_ID from the callspecs
_replace_list_contents(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
_replace_list_contents(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

0 comments on commit a511c3a

Please sign in to comment.