def flake8(session: PowerSession): """Launch flake8 qualimetry.""" session.install("-r", str(Folders.ci_tools / "flake8-requirements.txt")) session.install("genbadge[flake8]") session.run2("pip install -e .[flake8]") rm_folder(Folders.flake8_reports) Folders.flake8_reports.mkdir(parents=True, exist_ok=True) rm_file(Folders.flake8_intermediate_file) # Options are set in `setup.cfg` file session.run("flake8", pkg_name, "--exit-zero", "--format=html", "--htmldir", str(Folders.flake8_reports), "--statistics", "--tee", "--output-file", str(Folders.flake8_intermediate_file)) # generate our badge session.run2("genbadge flake8 -i %s -o %s" % (Folders.flake8_intermediate_file, Folders.flake8_badge)) rm_file(Folders.flake8_intermediate_file)
def tests(session: PowerSession, coverage, pkg_specs): """Run the test suite, including test reports generation and coverage reports. """ # As soon as this runs, we delete the target site and coverage files to avoid reporting wrong coverage/etc. rm_folder(Folders.site) rm_folder(Folders.reports_root) # delete the .coverage files if any (they are not supposed to be any, but just in case) rm_file(Folders.coverage_intermediate_file) rm_file(Folders.root / "coverage.xml") # CI-only dependencies # Did we receive a flag through positional arguments ? (nox -s tests -- <flag>) # install_ci_deps = False # if len(session.posargs) == 1: # assert session.posargs[0] == "keyrings.alt" # install_ci_deps = True # elif len(session.posargs) > 1: # raise ValueError("Only a single positional argument is accepted, received: %r" % session.posargs) # uncomment and edit if you wish to uninstall something without deleting the whole env # session.run2("pip uninstall pytest-asyncio --yes") # install all requirements session.install_reqs(setup=True, install=True, tests=True, versions_dct=pkg_specs) # install CI-only dependencies # if install_ci_deps: # session.install2("keyrings.alt") # list all (conda list alone does not work correctly on github actions) # session.run2("conda list") conda_prefix = Path(session.bin) if conda_prefix.name == "bin": conda_prefix = conda_prefix.parent session.run2("conda list", env={ "CONDA_PREFIX": str(conda_prefix), "CONDA_DEFAULT_ENV": session.get_session_id() }) # 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") # session.install("-e", ".", "--no-deps") # check that it can be imported even from a different folder # Important: do not surround the command into double quotes as in the shell ! session.run('python', '-c', 'import os; os.chdir(\'./docs/\'); import %s' % pkg_name) # finally run all tests if not coverage: # simple: pytest only session.run2("python -m pytest --cache-clear -v %s/tests/" % pkg_name) else: # coverage + junit html reports + badge generation session.install_reqs( phase="coverage", phase_reqs=["coverage", "pytest-html", "genbadge[tests,coverage]"], versions_dct=pkg_specs) # --coverage + junit html reports session.run2( "coverage run --source {pkg_name} " "-m pytest --cache-clear --junitxml={test_xml} --html={test_html} -v {pkg_name}/tests/" "".format(pkg_name=pkg_name, test_xml=Folders.test_xml, test_html=Folders.test_html)) session.run2("coverage report") session.run2( "coverage xml -o {covxml}".format(covxml=Folders.coverage_xml)) session.run2( "coverage html -d {dst}".format(dst=Folders.coverage_reports)) # delete this intermediate file, it is not needed anymore rm_file(Folders.coverage_intermediate_file) # --generates the badge for the test results and fail build if less than x% tests pass nox_logger.info("Generating badge for tests coverage") # Use our own package to generate the badge session.run2("genbadge tests -i %s -o %s -t 100" % (Folders.test_xml, Folders.test_badge)) session.run2("genbadge coverage -i %s -o %s" % (Folders.coverage_xml, Folders.coverage_badge))
def tests(session: PowerSession, coverage, pkg_specs): """Run the test suite, including test reports generation and coverage reports. """ # As soon as this runs, we delete the target site and coverage files to avoid reporting wrong coverage/etc. rm_folder(Folders.site) rm_folder(Folders.reports_root) # delete the .coverage files if any (they are not supposed to be any, but just in case) rm_file(Folders.root / ".coverage") rm_file(Folders.root / "coverage.xml") # CI-only dependencies # Did we receive a flag through positional arguments ? (nox -s tests -- <flag>) # install_ci_deps = False # if len(session.posargs) == 1: # assert session.posargs[0] == "keyrings.alt" # install_ci_deps = True # elif len(session.posargs) > 1: # raise ValueError("Only a single positional argument is accepted, received: %r" % session.posargs) # uncomment and edit if you wish to uninstall something without deleting the whole env # session.run2("pip uninstall pytest-asyncio --yes") # install all requirements session.install_reqs(setup=True, install=True, tests=True, versions_dct=pkg_specs) # install CI-only dependencies # if install_ci_deps: # session.install2("keyrings.alt") # list all (conda list alone does not work correctly on github actions) # session.run2("conda list") conda_prefix = Path(session.bin) if conda_prefix.name == "bin": conda_prefix = conda_prefix.parent session.run2("conda list", env={ "CONDA_PREFIX": str(conda_prefix), "CONDA_DEFAULT_ENV": session.get_session_id() }) # 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 ]) # finally run all tests if not coverage: # simple: pytest only session.run2("python -m pytest -v %s/tests/" % pkg_name) else: # coverage + junit html reports + badge generation session.install_reqs( phase="coverage", phase_reqs=["coverage", "pytest-html", "requests", "xunitparser"], versions_dct=pkg_specs) # --coverage + junit html reports # First the raw for coverage print("\n\n****** Running tests : 1/2 RAW (for coverage) ******\n\n") session.run2( "coverage run --source {pkg_name} " "-m pytest -v {pkg_name}/tests_raw/" "".format(pkg_name=pkg_name, dst=Folders.test_reports), success_codes=( 0, 1 ) # since some tests are purposedly failing we accept code 1 ) print( "\n\n****** Running tests : 2/2 META (appending to coverage) ******\n\n" ) session.run2( "coverage run --append --source {pkg_name} " "-m pytest --junitxml={dst}/junit.xml --html={dst}/report.html -v {pkg_name}/tests/" "".format(pkg_name=pkg_name, dst=Folders.test_reports)) # session.run2("coverage report") # this shows in terminal + fails under XX%, same as --cov-report term --cov-fail-under=70 # noqa session.run2( "coverage xml -o {covxml}".format(covxml=Folders.coverage_xml)) session.run2( "coverage html -d {dst}".format(dst=Folders.coverage_reports)) # delete this intermediate file, it is not needed anymore rm_file(Folders.root / ".coverage") # --generates the badge for the test results and fail build if less than x% tests pass nox_logger.info("Generating badge for tests coverage") session.run2("python ci_tools/generate-junit-badge.py 100 %s" % Folders.test_reports)