Skip to content

Coverage #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2025
Merged

Coverage #56

merged 5 commits into from
Mar 9, 2025

Conversation

MusicalNinjaDad
Copy link
Owner

@MusicalNinjaDad MusicalNinjaDad commented Mar 9, 2025

Fixes #53
Helps towards #34

Summary by Sourcery

Improve test coverage reporting by configuring the CI workflow to run coverage on multiple Python versions and upload the results to Codecov. Also, update the justfile to run coverage for all python versions.

CI:

  • Run coverage on multiple Python versions in CI and upload the results to Codecov.
  • Use a matrix strategy to run tests on multiple Python versions.
  • Configure Codecov to comment after 5 builds.
  • Fixes the coverage check workflow to use uv instead of pip

Tests:

  • Enable coverage for all python versions

Copy link
Contributor

sourcery-ai bot commented Mar 9, 2025

Reviewer's Guide by Sourcery

This pull request focuses on improving code coverage reporting. It configures the coverage check workflow to run on multiple Python versions, modifies the cov recipe in the justfile to generate combined coverage reports, updates the pyproject.toml file to use coverage instead of pytest-cov, and adds a codecov.yml file for Codecov configuration. Additionally, some # pragma: no cover statements were added.

Updated class diagram for ExampleDir

classDiagram
    class ExampleDir{
        +path: Path
        +pytester: Pytester
        +example_dir_cache: dict
        +conftest: str
        +ini: str
        +files: list[str]
        +__init__(path: Path, pytester: Pytester, example_dir_cache: dict, conftest: str, ini: str, files: list[str])
    }
    note for ExampleDir "Added pragma: no cover"
    class ExampleDirRequest{
        +param: ExampleDirSpec
        +__init__(param: ExampleDirSpec)
    }
    note for ExampleDirRequest "No changes"
    class ExampleDirSpec{
        +path: str
        +conftest: str
        +ini: str
        +files: list[str]
        +__init__(path: str, conftest: str, ini: str, files: list[str])
    }
    note for ExampleDirSpec "No changes"
Loading

File-Level Changes

Change Details Files
Configured the coverage check workflow to run on multiple Python versions using a matrix strategy.
  • Added a matrix strategy to run the coverage check on Python versions 3.9 through 3.13.
  • Modified the 'Set up Python' and 'Install uv' steps to use the matrixed Python version.
  • Replaced pytest with coverage to generate coverage reports.
.github/workflows/check-coverage.yml
Added # pragma: no cover to several lines.
  • Added # pragma: no cover to the ExampleDir class definition.
  • Added # pragma: no cover to the example_dir_cache fixture definition.
  • Added # pragma: no cover to conditional blocks in example_dir function.
pytest_ipynb2/_pytester_helpers.py
Modified the cov recipe in the justfile to run coverage for multiple Python versions and generate a combined report.
  • Added commands to erase previous coverage data and remove the pycov directory.
  • Added commands to run coverage for Python versions 3.9 through 3.13, appending the results.
  • Added commands to generate a coverage report and HTML report with context information.
justfile
Removed conditional pragma no cover for python versions.
  • Removed conditional # pragma: no cover for python versions in _cellpath.py.
pytest_ipynb2/_cellpath.py
Updated the pyproject.toml file to use coverage instead of pytest-cov and configured coverage settings.
  • Replaced pytest-cov with coverage in the cov_unique group.
  • Added dynamic_context = "test_function" to the [tool.coverage.run] section.
pyproject.toml
Added a codecov.yml file to configure Codecov.
  • Added a codecov.yml file to configure Codecov.
codecov.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#53 Ensure coverage finds module-level statements.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Mar 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (58f9f3d) to head (a6d7f3a).

Additional details and impacted files
@@             Coverage Diff              @@
##             main       #56       +/-   ##
============================================
+ Coverage   71.91%   100.00%   +28.08%     
============================================
  Files           4         4               
  Lines         349       340        -9     
  Branches       29        30        +1     
============================================
+ Hits          251       340       +89     
+ Misses         97         0       -97     
+ Partials        1         0        -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MusicalNinjaDad MusicalNinjaDad merged commit 0b2aac6 into main Mar 9, 2025
19 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the coverage branch March 9, 2025 18:24
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @MusicalNinjaDad - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using fail-fast: true in the matrix strategy to avoid running all Python versions if one fails.
  • The dynamic_context configuration in pyproject.toml might not be necessary given the context is already set in the command line.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Review instructions: 5 issues found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +71 to +79
uv run coverage erase
rm -rf pycov
uv run --python 3.13 coverage run --context=3.13 -m pytest
UV_PROJECT_ENVIRONMENT="./.venv-3.12" uv run --python 3.12 coverage run --context=3.12 --append -m pytest
UV_PROJECT_ENVIRONMENT="./.venv-3.11" uv run --python 3.11 coverage run --context=3.11 --append -m pytest
UV_PROJECT_ENVIRONMENT="./.venv-3.10" uv run --python 3.10 coverage run --context=3.10 --append -m pytest
UV_PROJECT_ENVIRONMENT="./.venv-3.9" uv run --python 3.9 coverage run --context=3.9 --append -m pytest
uv run coverage report
uv run coverage html --show-contexts -d pycov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Multiple similar coverage commands in the 'cov' target.

The repetitive commands for different Python versions work correctly, but consider refactoring or abstracting the common parts to simplify future maintenance if additional versions are supported.

Suggested implementation:

cov:
  uv run coverage erase
  rm -rf pycov
  for ver in 3.13 3.12 3.11 3.10 3.9; do \
    if [ "$ver" = "3.13" ]; then \
      uv run --python $ver coverage run --context=$ver -m pytest; \
    else \
      UV_PROJECT_ENVIRONMENT="./.venv-$ver" uv run --python $ver coverage run --context=$ver --append -m pytest; \
    fi; \
  done
  uv run coverage report
  uv run coverage html --show-contexts -d pycov

Ensure that your environment supports executing shell loops within the justfile. If not, you may need to wrap this loop in an external shell script and call it from the justfile.

@@ -21,7 +21,7 @@
with suppress(ImportError):
from typing import Self # not type-checking on python < 3.11 so don't care if this fails

if sys.version_info < (3, 10): # dataclass does not offer kw_only on python < 3.10 # pragma: no cover
if sys.version_info < (3, 10): # dataclass does not offer kw_only on python < 3.10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider using EAFP instead of LBYL for version checking

This version check is using Look Before You Leap (LBYL) pattern. Consider using Easier to Ask for Forgiveness than Permission (EAFP) by trying to import/use the feature directly and catching the exception if it fails. For example: try: ... except TypeError: # kw_only not supported

Review instructions:

Path patterns: **/*.py, **/*.ipynb

Instructions:
Prefer EAFP to LBYL in most cases

@@ -21,7 +21,7 @@

CELL_PREFIX: Final[str] = "Cell"

if sys.version_info < (3, 12): # pragma: no cover
if sys.version_info < (3, 12):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider using EAFP instead of LBYL for version checking

This version check is using Look Before You Leap (LBYL) pattern. Consider using Easier to Ask for Forgiveness than Permission (EAFP) by trying to use the feature directly and catching the exception if it fails.

Review instructions:

Path patterns: **/*.py, **/*.ipynb

Instructions:
Prefer EAFP to LBYL in most cases

@@ -43,7 +43,7 @@ def exists(self, *args: Any, **kwargs: Any) -> bool:
# TODO: #33 Extend `CellPath.exists` to also check that the cell exists (if performance allows)
return self.notebook.exists(*args, **kwargs)

if sys.version_info < (3, 13): # pragma: no cover
if sys.version_info < (3, 13):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider using EAFP instead of LBYL for version checking

This version check is using Look Before You Leap (LBYL) pattern. Consider using Easier to Ask for Forgiveness than Permission (EAFP) by trying to use the feature directly and catching the exception if it fails.

Review instructions:

Path patterns: **/*.py, **/*.ipynb

Instructions:
Prefer EAFP to LBYL in most cases

@@ -257,10 +257,10 @@ def example_dir(
example = request.param
if (cached_dir := example_dir_cache.get(example)) is None:
(pytester.path / example.path).mkdir(parents=True, exist_ok=True)
if example.conftest:
if example.conftest: # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider using EAFP instead of LBYL for attribute checking

This is using Look Before You Leap (LBYL) to check if the attribute exists or has a truthy value. Consider if an EAFP approach would be more appropriate here.

Review instructions:

Path patterns: **/*.py, **/*.ipynb

Instructions:
Prefer EAFP to LBYL in most cases

pytester.makeconftest(request.param.conftest)

if example.ini:
if example.ini: # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider using EAFP instead of LBYL for attribute checking

This is using Look Before You Leap (LBYL) to check if the attribute exists or has a truthy value. Consider if an EAFP approach would be more appropriate here.

Review instructions:

Path patterns: **/*.py, **/*.ipynb

Instructions:
Prefer EAFP to LBYL in most cases

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.

Fix coverage not finding module-level statements
1 participant