Commit 71442642 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Merge branch 'enhancement/migrate_to_pytest' into 'master'

Enhancement/migrate to pytest

See merge request !30
parents 1020bbbf f1065f24
Pipeline #36286 passed with stages
in 10 minutes
# .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
...@@ -13,18 +13,25 @@ test_geoarray: ...@@ -13,18 +13,25 @@ test_geoarray:
script: script:
- source /root/mambaforge/bin/activate ci_env - source /root/mambaforge/bin/activate ci_env
- pip install pytest pytest-cov pytest-reporter-html1 # TODO remove after recreating CI runner
# update py_tools_ds # update py_tools_ds
- pip install -U py_tools_ds -q - pip install -U py_tools_ds -q
# run tests # run tests
- make nosetests - make pytest
- make docs - make docs
artifacts: artifacts:
expose_as: 'Test and coverage report'
paths: paths:
- htmlcov/ - htmlcov/
- report.html
- docs/_build/html/ - docs/_build/html/
- nosetests.html reports:
- nosetests.xml cobertura: coverage.xml
junit: report.xml
expire_in: 30 days
when: always when: always
...@@ -83,7 +90,7 @@ pages: # this job must be called 'pages' to advise GitLab to upload content to ...@@ -83,7 +90,7 @@ pages: # this job must be called 'pages' to advise GitLab to upload content to
- mkdir public - mkdir public
- mkdir -p public/doc - mkdir -p public/doc
- mkdir -p public/coverage - mkdir -p public/coverage
- mkdir -p public/nosetests_reports - mkdir -p public/test_reports
# Copy over the docs # Copy over the docs
- cp -r docs/_build/html/* public/doc/ - cp -r docs/_build/html/* public/doc/
...@@ -91,14 +98,14 @@ pages: # this job must be called 'pages' to advise GitLab to upload content to ...@@ -91,14 +98,14 @@ pages: # this job must be called 'pages' to advise GitLab to upload content to
# Copy over the coverage reports # Copy over the coverage reports
- cp -r htmlcov/* public/coverage/ - cp -r htmlcov/* public/coverage/
# Copy over the nosetests reports # Copy over the test reports
- cp nosetests.* public/nosetests_reports/ - cp report.html public/test_reports/
# Check if everything is working great # Check if everything is working great
- ls -al public - ls -al public
- ls -al public/doc - ls -al public/doc
- ls -al public/coverage - ls -al public/coverage
- ls -al public/nosetests_reports - ls -al public/test_reports
artifacts: artifacts:
paths: paths:
- public - public
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
History History
======= =======
0.15.6 (16.12.2021)
-------------------
* Migrated test calls from nosetests to pytest.
0.15.5 (03.12.2021) 0.15.5 (03.12.2021)
------------------- -------------------
......
.PHONY: clean clean-test clean-pyc clean-build docs help nosetests .PHONY: clean clean-test clean-pyc clean-build docs help pytest
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
define BROWSER_PYSCRIPT define BROWSER_PYSCRIPT
import os, webbrowser, sys import os, webbrowser, sys
...@@ -47,8 +47,10 @@ clean-test: ## remove test and coverage artifacts ...@@ -47,8 +47,10 @@ clean-test: ## remove test and coverage artifacts
rm -fr .tox/ rm -fr .tox/
rm -fr .coverage.* rm -fr .coverage.*
rm -fr htmlcov/ rm -fr htmlcov/
rm -fr nosetests.html rm -fr report.html
rm -fr nosetests.xml rm -fr report.xml
rm -fr coverage.xml
rm -fr .pytest_cache
lint: ## check style with flake8 lint: ## check style with flake8
flake8 --max-line-length=120 geoarray tests > ./tests/linting/flake8.log || \ flake8 --max-line-length=120 geoarray tests > ./tests/linting/flake8.log || \
...@@ -73,12 +75,22 @@ coverage: clean-test ## check code coverage quickly with the default Python ...@@ -73,12 +75,22 @@ coverage: clean-test ## check code coverage quickly with the default Python
coverage html coverage html
# $(BROWSER) htmlcov/index.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' ## - puts the coverage results in the folder 'htmlcov'
## - generates 'nosetests.html' (--with-html) ## - generates cobertura 'coverage.xml' (needed to show coverage in GitLab MR changes)
## - generates 'nosetests.xml' (--with-xunit) which is currently not visualizable by GitLab ## - generates 'report.html' based on pytest-reporter-html1
nosetests -vv --with-coverage --cover-package=geoarray --cover-erase --cover-html --cover-html-dir=htmlcov \ ## - generates JUnit 'report.xml' to show the test report as a new tab in a GitLab MR
--with-html --with-xunit --rednose --force-color ## 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=geoarray \
--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 docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/geoarray.rst rm -f docs/geoarray.rst
......
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
# limitations under the License. # limitations under the License.
__version__ = '0.15.5' __version__ = '0.15.6'
__versionalias__ = '20211203.01' __versionalias__ = '20211216.01'
...@@ -58,7 +58,7 @@ req_interactive_plotting = [ ...@@ -58,7 +58,7 @@ req_interactive_plotting = [
req_setup = ['setuptools-git'] req_setup = ['setuptools-git']
req_test = req + ["coverage", "nose", "nose2", "nose-htmloutput", "rednose", "urlchecker", "parameterized"] req_test = req + ["pytest", "pytest-cov", "pytest-reporter-hmtl1", "urlchecker", "parameterized"]
req_doc = ['sphinx-argparse', 'sphinx_rtd_theme'] req_doc = ['sphinx-argparse', 'sphinx_rtd_theme']
......
...@@ -23,15 +23,13 @@ dependencies: ...@@ -23,15 +23,13 @@ dependencies:
- pyepsg # optional dependency of cartopy, needed by geoarray - pyepsg # optional dependency of cartopy, needed by geoarray
# test/docs requirements # test/docs requirements
- coverage
- flake8 - flake8
- parameterized - parameterized
- pycodestyle - pycodestyle
- pydocstyle - pydocstyle
- pylint - pylint
- nose - pytest
- nose2 - pytest-cov
- nose-htmloutput - pytest-reporter-html1
- rednose
- sphinx-argparse - sphinx-argparse
- urlchecker - urlchecker
...@@ -734,3 +734,8 @@ class Test_GeoArray(TestCase): ...@@ -734,3 +734,8 @@ class Test_GeoArray(TestCase):
[-9999, -9999], [-9999, -9999],
[5352, 5766], [5352, 5766],
[5080, 5436]]).reshape(shape_exp))) [5080, 5436]]).reshape(shape_exp)))
if __name__ == '__main__':
import pytest
pytest.main()
...@@ -65,3 +65,8 @@ class Test_BadDataMask(TestCase): ...@@ -65,3 +65,8 @@ class Test_BadDataMask(TestCase):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
BadDataMask(np.array([[5, 2], [2, 5]])) BadDataMask(np.array([[5, 2], [2, 5]]))
if __name__ == '__main__':
import pytest
pytest.main()
...@@ -90,3 +90,8 @@ class Test_GDAL_Metadata(TestCase): ...@@ -90,3 +90,8 @@ class Test_GDAL_Metadata(TestCase):
for bN in gA.bandnames.keys(): for bN in gA.bandnames.keys():
self.assertTrue(bN in content, msg="The band name '%s' is not in the written header. " self.assertTrue(bN in content, msg="The band name '%s' is not in the written header. "
"Header contains: \n\n%s" % (bN, content)) "Header contains: \n\n%s" % (bN, content))
if __name__ == '__main__':
import pytest
pytest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment