Skip to content

Conversation

@dmitriyrepin
Copy link
Contributor

@dmitriyrepin dmitriyrepin commented Sep 25, 2025

Closes #574

Remove the tests source code (tests/) from the codebase used for the mdio-python package code coverage calculations.

Notes:

  • This PR reduces the package coverage codebase from 4,500 to 2,219 statements.
  • The package code coverage might fall with this PR: removing almost 100%-covered tests code might reduce the figure for the overall package code coverage.

This PR:

  • Adds pytest-cov to the dev dependency-groups in order to allow measuring code coverage with VS Code
  • Excludes tests/ from the code coverage. (NOTE: setting source = ["src/mdio"] is not enough and omit needs to be used)

Before:

  • NOX
Run nox --session=coverage
nox > Running session coverage
Installed Python 3.13.7 in 22ms
 + cpython-3.13.7-linux-x86_64-gnu (python3.13)
nox > Creating virtual environment (uv) using python3.13 in .nox/coverage
nox > uv export --only-dev --no-hashes -o .nox/coverage/tmp/requirements.txt
nox > uv pip install 'coverage[toml]' --constraint .nox/coverage/tmp/requirements.txt
nox > coverage combine
Combined data file .coverage.Mac-1758731966514.local.2022.XlBoVagx
Combined data file .coverage.runnervmbe3js.4092.XPJvtkDx
Combined data file .coverage.runnervmf4ws1.2191.XXnivYMx
Combined data file .coverage.runnervmf4ws1.2198.XUVVNufx
Skipping duplicate data .coverage.runnervmf4ws1.2342.XGtKsvMx
nox > coverage report
Name                                                       Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------------------------------
src/mdio/__init__.py                                          10      2      0      0    80%   12-13
src/mdio/__main__.py                                          44     24      8      0    38%   40-47, 51-65, 72-73
...
src/mdio/segy/parsers.py                                      31      0      4      1    97%   68->77
src/mdio/segy/utilities.py                                    51      1     10      2    95%   77->80, 86
tests/__init__.py                                              0      0      0      0   100%
tests/conftest.py                                             41      9     10      4    71%   26, 40-41, 53, 60-62, 69-70
...
tests/unit/v1/test_dataset_serializer.py                     154      7     10      1    95%   38, 250-255
------------------------------------------------------------------------------------------------------
TOTAL                                                       4500    516    584     80    87%
nox > Session coverage was successful.
  • VS Code
================================ tests coverage ================================
_______________ coverage: platform linux, python 3.13.5-final-0 ________________

Name                                                       Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------------------------------
noxfile.py                                                   132    132     40      0     0%   3-274
src/mdio/__init__.py                                          10      2      0      0    80%   12-13
src/mdio/__main__.py                                          44     24      8      0    38%   40-47, 51-65, 72-73
...
src/mdio/segy/parsers.py                                      31      0      4      1    97%   68->77
src/mdio/segy/utilities.py                                    51      1     10      2    95%   77->80, 86
tests/__init__.py                                              0      0      0      0   100%
tests/conftest.py                                             43     11     10      4    68%   26-28, 42-43, 55, 62-64, 71-72
...
tests/unit/v1/test_dataset_builder_helpers.py                 15      0      0      0   100%
tests/unit/v1/test_dataset_serializer.py                     154      7     10      1    95%   38, 250-255
------------------------------------------------------------------------------------------------------
TOTAL                                                       4419    504    610     81    86%
Required test coverage of 85.0% reached. Total coverage: 86.14%
================== 178 passed, 12 skipped in 61.85s (0:01:01) ==================

After

  • NOX
Run nox --session=coverage
nox > Running session coverage
Installed Python 3.13.7 in 22ms
 + cpython-3.13.7-linux-x86_64-gnu (python3.13)
nox > Creating virtual environment (uv) using python3.13 in .nox/coverage
nox > uv export --only-dev --no-hashes -o .nox/coverage/tmp/requirements.txt
nox > uv pip install 'coverage[toml]' --constraint .nox/coverage/tmp/requirements.txt
nox > coverage combine
Combined data file .coverage.runnervm3ublj.2233.XQoKNNhx
Skipping duplicate data .coverage.runnervm3ublj.2245.XQvtQbJx
Combined data file .coverage.runnervm3ublj.2246.XORxRNpx
Combined data file .coverage.runnervm747y6.1340.XzSeRsFx
Combined data file .coverage.sat12-bq152-da46c735-6d0d-4c5b-886a-f3b8cfcc49d0-DA37D04C399C.local.1492.XIXJhZVx
nox > coverage report
Name                                                      Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------------------------------
src/mdio/__init__.py                                         10      2      0      0    80%   12-13
src/mdio/__main__.py                                         44     24      8      0    38%   40-47, 51-65, 72-73
...
src/mdio/segy/utilities.py                                   51      1     10      2    95%   77->80, 86
-----------------------------------------------------------------------------------------------------
TOTAL                                                      2219    416    426     63    79%
Coverage failure: total of 79 is less than fail-under=85
nox > Command coverage report failed with exit code 2
nox > Session coverage failed.
Error: Process completed with exit code 1.
  • VS Code
================================ tests coverage ================================
_______________ coverage: platform linux, python 3.13.5-final-0 ________________

Name                                                      Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------------------------------
src/mdio/__init__.py                                         10      2      0      0    80%   12-13
src/mdio/__main__.py                                         44     24      8      0    38%   40-47, 51-65, 72-73
...
src/mdio/segy/parsers.py                                     31      0      4      1    97%   68->77
src/mdio/segy/utilities.py                                   51      1     10      2    95%   77->80, 86
-----------------------------------------------------------------------------------------------------
TOTAL                                                      2099    270    414     64    84%
FAIL Required test coverage of 85.0% not reached. Total coverage: 84.08%
================== 178 passed, 12 skipped in 62.18s (0:01:02) ==================

@BrianMichell BrianMichell changed the title Exclude test source from coverage (see issue #574) Exclude test source from coverage Sep 30, 2025
@tasansal
Copy link
Collaborator

tasansal commented Oct 3, 2025

This is great but once we excluded the tests, the coverage falls below our threshold. Mainly because CLI code is not tested anymore since we need to re-implement it. Can you remove all the CLI code and CLI documentation for now. Then coverage should be fine. We can always get it back from the old tags if needed.

@tasansal tasansal force-pushed the exclude-test-source-from-coverage branch from f40e60f to 1ecec6d Compare October 3, 2025 20:03
@tasansal tasansal force-pushed the exclude-test-source-from-coverage branch from a5c476f to 5070c47 Compare October 8, 2025 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclusions for code coverage

2 participants