From ff2da46b07b98b27b3d799f46742430117d08545 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Wed, 26 Jun 2024 17:22:09 -0400 Subject: [PATCH] Replace stestr with pytest Using pytest instead of stestr to run the tests gives us access to a broad range of test plugins and convenient testing features like pytest fixtures. This commit includes the pytest-cov plugin for code coverage reporting; running the unit tests via `tox -e py3` will produce coverage statistics on stdout. --- .coveragerc | 10 ++++++++++ .github/workflows/unit-tests.yaml | 4 ++-- .gitignore | 1 + .stestr.conf | 3 --- pytest.ini | 5 +++++ test-requirements.txt | 3 ++- tox.ini | 12 +----------- 7 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 .coveragerc delete mode 100644 .stestr.conf create mode 100644 pytest.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..92d6f59a --- /dev/null +++ b/.coveragerc @@ -0,0 +1,10 @@ +[run] +branch = True + +[report] +ignore_errors = True +omit = + esi_leap/tests/* + +[html] +directory = coverage_html_report diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 64d1b566..6011a78a 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -1,9 +1,9 @@ -name: esi-leap +name: Unit tests on: [push, pull_request] jobs: - build: + run-unit-tests: runs-on: ubuntu-20.04 strategy: diff --git a/.gitignore b/.gitignore index 6c71e85d..0c09cc0a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__/ .tox/ *.swp etc/esi-leap/esi-leap.conf.sample +.coverage/ diff --git a/.stestr.conf b/.stestr.conf deleted file mode 100644 index 08159101..00000000 --- a/.stestr.conf +++ /dev/null @@ -1,3 +0,0 @@ -[DEFAULT] -test_path=${TESTS_DIR:-./esi_leap/tests/} -top_dir=./ diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..ea256aa7 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +# Suppress DeprecationWarnings in third party modules +filterwarnings = + ignore::DeprecationWarning + default:::esi_leap: diff --git a/test-requirements.txt b/test-requirements.txt index fca675b5..be2a14f4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,8 +11,9 @@ PyMySQL>=0.7.6 # MIT License iso8601>=0.1.11 # MIT oslotest>=3.2.0 # Apache-2.0 osprofiler>=1.5.0 # Apache-2.0 -stestr>=1.0.0 # Apache-2.0 psycopg2>=2.6.2 # LGPL/ZPL +pytest>=8.2.0 # MIT +pytest-cov>=5.0.0 # MIT testtools>=2.2.0 # MIT testresources>=2.0.0 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD diff --git a/tox.ini b/tox.ini index 9958320f..0c3ed2f8 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ setenv = VIRTUAL_ENV={envdir} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt -commands = stestr run {posargs} +commands = pytest -v --cov=esi_leap {posargs} [testenv:pep8] commands = flake8 esi_leap {posargs} @@ -24,16 +24,6 @@ commands = flake8 esi_leap {posargs} [testenv:venv] commands = {posargs} -[testenv:cover] -setenv = - VIRTUAL_ENV={envdir} - PYTHON=coverage run --source esi_leap --parallel-mode -commands = - stestr run {posargs} - coverage combine - coverage html -d cover - coverage xml -o cover/coverage.xml - [testenv:docs] deps = -r{toxinidir}/doc/requirements.txt commands = sphinx-build -W -b html doc/source doc/build/html