Skip to content
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

Test suite tidy #319

Merged
merged 24 commits into from
Aug 4, 2023
Merged

Test suite tidy #319

merged 24 commits into from
Aug 4, 2023

Conversation

williamjameshandley
Copy link
Collaborator

Description

This PR begins a long road to upgrading the test suite with more systematic parametrisation. First step is to move to skipping tests rather than using 'if' statements, which the first commit does.

Fixes #110

Checklist:

  • I have performed a self-review of my own code
  • My code is PEP8 compliant (flake8 anesthetic tests)
  • My code contains compliant docstrings (pydocstyle --convention=numpy anesthetic)
  • New and existing unit tests pass locally with my changes (python -m pytest)
  • I have added tests that prove my fix is effective or that my feature works
  • I have appropriately incremented the semantic version number in both README.rst and anesthetic/_version.py

@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4a35d6e) 100.00% compared to head (8c8b721) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #319   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           33        33           
  Lines         2807      2805    -2     
=========================================
- Hits          2807      2805    -2     
Files Changed Coverage Δ
anesthetic/_version.py 100.00% <100.00%> (ø)
anesthetic/convert.py 100.00% <100.00%> (ø)
anesthetic/plot.py 100.00% <100.00%> (ø)
anesthetic/read/ultranest.py 100.00% <100.00%> (ø)

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

@williamjameshandley williamjameshandley added the tests Collection of fixes/features for test suite upgrades label Jul 25, 2023
Copy link
Collaborator

@lukashergt lukashergt left a comment

Choose a reason for hiding this comment

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

See some comments inline.

anesthetic/read/ultranest.py Outdated Show resolved Hide resolved
tests/test_convert.py Show resolved Hide resolved
tests/utils.py Outdated Show resolved Hide resolved
tests/test_plot.py Show resolved Hide resolved
tests/test_plot.py Show resolved Hide resolved
tests/test_reader.py Show resolved Hide resolved
tests/test_reader.py Show resolved Hide resolved
Comment on lines -402 to +392
@pytest.mark.xfail('astropy' not in sys.modules,
raises=ImportError,
reason="requires astropy package")
@astropy_mark_xfail
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this test be simply skipped rather than xfailed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we don't run it, then we miss 100% coverage -- one could write specific tests which check for failure, but I think this is neater.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really miss 100% coverage? Normally our CI should be set up such that extras: true runs all tests without any skipping which gives us the 100% coverage. extras: false tests the minimal anesthetic version and is allowed to have less than 100% coverage.

That is why the coverage tests often initially show up as failed, because the faster extras: false CI jobs finish first with insufficient coverage and we have to wait for the first extras: true to run through to get 100% coverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've changed xfails to skips so you can see the problem at this permalink

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, ok, thanks. It is the try-except blocks in those tests, where we provide informative error messages if a package is not installed, e.g.:

    try:
        import getdist
    except ModuleNotFoundError:
        raise ImportError("You need to install getdist to use to_getdist")

So in this getdist example the xfail with condition runs the actual test if getdist is installed (where codecov misses the except block) and checks for this ImportError if it is not (where codecov hits the except block).

@williamjameshandley williamjameshandley marked this pull request as ready for review August 1, 2023 21:43
Copy link
Collaborator

@lukashergt lukashergt left a comment

Choose a reason for hiding this comment

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

More comments inline.

anesthetic/samples.py Outdated Show resolved Hide resolved
Comment on lines -402 to +392
@pytest.mark.xfail('astropy' not in sys.modules,
raises=ImportError,
reason="requires astropy package")
@astropy_mark_xfail
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really miss 100% coverage? Normally our CI should be set up such that extras: true runs all tests without any skipping which gives us the 100% coverage. extras: false tests the minimal anesthetic version and is allowed to have less than 100% coverage.

That is why the coverage tests often initially show up as failed, because the faster extras: false CI jobs finish first with insufficient coverage and we have to wait for the first extras: true to run through to get 100% coverage.

Copy link
Collaborator

@lukashergt lukashergt left a comment

Choose a reason for hiding this comment

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

Thanks @williamjameshandley, please squash and merge.

Comment on lines -402 to +392
@pytest.mark.xfail('astropy' not in sys.modules,
raises=ImportError,
reason="requires astropy package")
@astropy_mark_xfail
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, ok, thanks. It is the try-except blocks in those tests, where we provide informative error messages if a package is not installed, e.g.:

    try:
        import getdist
    except ModuleNotFoundError:
        raise ImportError("You need to install getdist to use to_getdist")

So in this getdist example the xfail with condition runs the actual test if getdist is installed (where codecov misses the except block) and checks for this ImportError if it is not (where codecov hits the except block).

@williamjameshandley
Copy link
Collaborator Author

Many thanks @lukashergt

@williamjameshandley williamjameshandley merged commit dc15c5b into master Aug 4, 2023
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Collection of fixes/features for test suite upgrades
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change all for-loops in unit tests to parametrised tests
2 participants