Skip to content

Commit

Permalink
setup : add pytest-html for report files
Browse files Browse the repository at this point in the history
  • Loading branch information
lecontm committed Feb 27, 2024
1 parent b0c340b commit 200324a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pandora2d_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
pip install pytest
pip install pytest-cov
pip install pytest-mock
pip install pytest-html
pip install codecov
pip install build
- name: Install Pandora2d
Expand All @@ -31,7 +32,8 @@ jobs:
- name: Test with pytest
run: |
export NUMBA_DISABLE_JIT="1"
pytest --junitxml=pytest-report.xml --cov-config=.coveragerc --cov-report xml --cov
pytest -m "unit_tests" --html=unit-test-report.html --cov-config=.coveragerc --cov-report xml --cov
pytest -m "functional_tests" --html=functional-test-report.html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
- name: Create source distrubition
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ test-all: install test-unit test-functional test-resource test-performance ## ru
.PHONY: test-unit
test-unit: install ## run unit tests only (for dev) + coverage (source venv before)
@echo "Run unit tests"
@${PANDORA2D_VENV}/bin/pytest -m "unit_tests" --junitxml=pytest-report.xml --cov-config=.coveragerc --cov-report xml --cov
@${PANDORA2D_VENV}/bin/pytest -m "unit_tests" --html=unit-test-report.html --cov-config=.coveragerc --cov-report xml --cov

.PHONY: test-functional
test-functional: install ## run functional tests only (for dev and validation plan)
@echo "Run functional tests"
@${PANDORA2D_VENV}/bin/pytest -m "functional_tests"
@${PANDORA2D_VENV}/bin/pytest -m "functional_tests" --html=functional-test-report.html

.PHONY: test-resource
test-resource: install ## run resource tests only (for validation plan)
@echo "Run resource tests"
@rm -f tests/resource_tests/.pymon
@${PANDORA2D_VENV}/bin/pytest -m "resource_tests and not metrics" --db tests/resource_tests/.pymon
@${PANDORA2D_VENV}/bin/pytest tests/resource_tests/test_metrics.py --database tests/resource_tests/.pymon
@${PANDORA2D_VENV}/bin/pytest tests/resource_tests/test_metrics.py --database tests/resource_tests/.pymon --html=resource-test-report.html

.PHONY: test-performance
test-performance: install ## run performance tests only (for validation plan)
@echo "Run performance tests"
@${PANDORA2D_VENV}/bin/pytest -m "performance_tests"
@${PANDORA2D_VENV}/bin/pytest -m "performance_tests" --html=performance-test-report.html

## Code quality, linting section

Expand Down Expand Up @@ -182,11 +182,11 @@ clean-test:
@rm -rf coverage.xml
@rm -fr htmlcov/
@rm -fr .pytest_cache
@rm -f pytest-report.xml
@rm -f pylint-report.txt
@rm -f debug.log
@rm -f .pymon
@rm -f tests/resource_tests/.pymon
@rm -f *-test-report.html

.PHONY: clean-doc
clean-doc:
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ markers =
functional_tests: functional tests
resource_tests: resource tests
performance_tests: accuracy tests
norecursedirs = .git doc conf .gitlab
norecursedirs = .git doc conf .gitlab
generate_report_on_test = True
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dev =
pytest-cov
pytest-mock
pytest-monitor
pytest-html
pre-commit
isort>=5.8.0 # Check imports
black>=21.5b0 # PEP8 format code
Expand Down
30 changes: 29 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021 Centre National d'Etudes Spatiales (CNES).
# Copyright (c) 2024 Centre National d'Etudes Spatiales (CNES).
#
# This file is part of PANDORA2D
#
Expand All @@ -21,6 +21,7 @@
"""

import pathlib
import re
import pytest


Expand All @@ -46,6 +47,33 @@ def pytest_collection_modifyitems(config, items):
item.add_marker(pytest.mark.monitor_skip_test)


def pytest_html_results_table_header(cells):
"""
Add columns to html reports:
1. Category : with values {'TU', 'TF', 'TP', 'TR'}
2. Function tested : basename of python test file
"""
cells.insert(1, "<th>Category</th>")
cells.insert(2, "<th>Function tested</th>")


def pytest_html_results_table_row(report, cells):
"""
Complete columns to html reports with regex pattern :
"tests/<CATEGORY>_tests/.../tests_<FUNCTION>.py::tests"
1. CATEGORY : with values {'TU', 'TF', 'TP', 'TR'}
2. FUNCTION : basename of python test file
"""
type_dict = {"unit": "TU", "functional": "TF", "resource": "TR", "performance": "TP"}
pattern = r"tests/(?P<type>\w+)_tests.*test_(?P<function>\w+)\.py"
match = re.match(pattern, report.nodeid)
cells.insert(1, f"<td>{type_dict[match.groupdict()['type']]}</td>")
cells.insert(2, f"<td>{match.groupdict()['function']}</td>")


@pytest.fixture()
def classic_config():
return "./tests/data/json_conf_files/classic_cfg.json"

0 comments on commit 200324a

Please sign in to comment.