Skip to content
Snippets Groups Projects
Commit 142d39c9 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Migrate to pytest.

parent 364d07b6
Branches
Tags
1 merge request!8Switch to pytest
Pipeline #46412 passed
# .coveragerc to control coverage.py
[run]
branch = False
concurrency = multiprocessing
parallel = True
omit = */site-packages/*,*/tests/*,*/.eggs/*
[report]
show_missing = True
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ignore_errors = True
[html]
directory = htmlcov
......@@ -12,18 +12,28 @@ test_pyrsr:
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
script:
- source /root/mambaforge/bin/activate ci_env
- make nosetests
- pip install pytest pytest-cov pytest-reporter-html1 sphinx_rtd_theme sphinx-autodoc-typehints # TODO remove after recreating CI runner
# run tests
- make pytest
# create the docs
- pip install sphinx_rtd_theme # Read-the-docs theme for SPHINX documentation
- pip install sphinx-autodoc-typehints
- make docs
artifacts:
expose_as: 'Test and coverage report'
paths:
- htmlcov/
- report.html
- docs/_build/html/
- nosetests.html
- nosetests.xml
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: report.xml
expire_in: 30 days
when: always
......@@ -82,7 +92,7 @@ pages: # this job must be called 'pages' to advise GitLab to upload content to
- mkdir public
- mkdir -p public/doc
- mkdir -p public/coverage
- mkdir -p public/nosetests_reports
- mkdir -p public/test_reports
# Copy over the docs
- cp -r docs/_build/html/* public/doc/
......@@ -90,14 +100,14 @@ pages: # this job must be called 'pages' to advise GitLab to upload content to
# Copy over the coverage reports
- cp -r htmlcov/* public/coverage/
# Copy over the nosetests reports
- cp nosetests.* public/nosetests_reports/
# Copy over the test reports
- cp report.html public/test_reports/
# Check if everything is working great
- ls -al public
- ls -al public/doc
- ls -al public/coverage
- ls -al public/nosetests_reports
- ls -al public/test_reports
artifacts:
paths:
- public
......
.PHONY: clean clean-test clean-pyc clean-build docs help
.PHONY: clean clean-test clean-pyc clean-build docs help pytest
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
......@@ -51,8 +51,11 @@ clean-test: ## remove test and coverage artifacts
rm -f .coverage
rm -fr .coverage.*
rm -fr htmlcov/
rm -fr nosetests.html
rm -fr nosetests.xml
rm -fr report.html
rm -fr report.xml
rm -fr coverage.xml
rm -fr .pytest_cache
lint: ## check style with flake8
flake8 --max-line-length=120 pyrsr tests > ./tests/linting/flake8.log || \
......@@ -78,12 +81,22 @@ coverage: ## check code coverage quickly with the default Python
coverage html
# $(BROWSER) htmlcov/index.html
nosetests: clean-test ## Runs nosetests with coverage, xUnit and nose-html-output
pytest: clean-test ## Runs pytest with coverage and creates coverage and test report
## - puts the coverage results in the folder 'htmlcov'
## - generates 'nosetests.html' (--with-html)
## - generates 'nosetests.xml' (--with-xunit) which is currently not visualizable by GitLab
nosetests -vv --with-coverage --cover-package=pyrsr --cover-package=bin --cover-erase --cover-html \
--cover-html-dir=htmlcov --with-html --with-xunit --rednose --force-color
## - generates cobertura 'coverage.xml' (needed to show coverage in GitLab MR changes)
## - generates 'report.html' based on pytest-reporter-html1
## - generates JUnit 'report.xml' to show the test report as a new tab in a GitLab MR
## NOTE: additional options pytest and coverage (plugin pytest-cov) are defined in .pytest.ini and .coveragerc
pytest tests \
--verbosity=3 \
--color=yes \
--tb=short \
--cov=pyrsr \
--cov-report html:htmlcov \
--cov-report term-missing \
--cov-report xml:coverage.xml \
--template=html1/index.html --report=report.html \
--junitxml report.xml
docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/pyrsr.rst
......
......@@ -25,7 +25,7 @@ Status
.. image:: https://img.shields.io/pypi/dm/pyrsr.svg
:target: https://pypi.python.org/pypi/pyrsr
See also the latest coverage_ report and the nosetests_ HTML report.
See also the latest coverage_ report and the pytest_ HTML report.
Features
......@@ -97,4 +97,4 @@ This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypack
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
.. _coverage: https://geomultisens.git-pages.gfz-potsdam.de/pyrsr/coverage/
.. _nosetests: https://geomultisens.git-pages.gfz-potsdam.de/pyrsr/nosetests_reports/nosetests.html
.. _pytest: https://geomultisens.git-pages.gfz-potsdam.de/pyrsr/test_reports/report.html
......@@ -42,7 +42,7 @@ requirements = ['numpy', 'pandas', 'matplotlib', 'scipy']
setup_requirements = ['setuptools-git'] # needed for package_data version controlled by GIT
test_requirements = ['coverage', 'nose', 'nose-htmloutput', 'rednose', 'urlchecker']
test_requirements = ['pytest', 'pytest-cov', 'pytest-reporter-html1', 'urlchecker']
setup(
......
......@@ -14,14 +14,14 @@ dependencies:
- scipy
# test and doc dependencies
- coverage
- flake8
- nose
- nose2
- nose-htmloutput
- pycodestyle
- pylint
- pydocstyle
- rednose
- pytest
- pytest-cov
- pytest-reporter-html1
- sphinx-argparse
- sphinx_rtd_theme
- sphinx-autodoc-typehints
- urlchecker
......@@ -125,3 +125,8 @@ class Test_get_LayerBandsAssignment(unittest.TestCase):
LBA = get_LayerBandsAssignment('Sentinel-2A', 'MSI', after_ac=True)
self.assertEqual(len(LBA), 11)
self.assertEqual(LBA, ['1', '2', '3', '4', '5', '6', '7', '8', '8A', '11', '12'])
if __name__ == '__main__':
import pytest
pytest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment