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

Add nox sessions for running tests #2681

Merged
merged 13 commits into from
May 13, 2024
Merged

Conversation

namurphy
Copy link
Member

@namurphy namurphy commented May 9, 2024

This PR adds a tests 🧪 session to noxfile.py which would let us run pytest. This is intended to replace the current tox environments for running tests.

The tests session is parametrized across versions of Python and for:

  • Running all tests (all)
  • Running tests except slow tests (skipslow)
  • Running all tests with code coverage (cov)
  • Running all tests against the minimum versions of direct dependencies (lowest-direct).

I set it so that doctests are run only against the newest supported versions of Python and dependencies. Doctests are not run when code coverage is being performed, since it helps to make sure that the test suite itself is testing everything we need it to.

We are currently running the tox equivalents of the following sessions in our CI:

  • tests-3.10(lowest-direct)
  • tests-3.11(cov)
  • tests-3.12(skipslow)

By default, running nox would run the test session for the current version of Python, skipping slow tests. I suspect that this would be the most frequently run nox session.

@github-actions github-actions bot added testing CI Related to continuous integration labels May 9, 2024
tox.ini Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.21%. Comparing base (f35d5b3) to head (3c16fd3).
Report is 1 commits behind head on main.

❗ Current head 3c16fd3 differs from pull request most recent head 58d7f29. Consider uploading reports for the commit 58d7f29 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2681      +/-   ##
==========================================
+ Coverage   94.88%   95.21%   +0.32%     
==========================================
  Files         103      103              
  Lines        9412     9412              
  Branches     2155     2155              
==========================================
+ Hits         8931     8962      +31     
+ Misses        299      273      -26     
+ Partials      182      177       -5     

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

Comment on lines +63 to +66
category_version_resolution: list[tuple[str, str, str]] = [
("tests", version, resolution)
for version in supported_python_versions
for resolution in ("highest", "lowest-direct")
Copy link
Member Author

Choose a reason for hiding this comment

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

Prior to this change, a requirements file was only created for the lowest-direct option for Python 3.10. With this change, this is now done for all supported versions of Python. This change will enable us to test PlasmaPy against the lowest versions of direct dependencies for all versions of Python (in our weekly tests).

Comment on lines +119 to +128
test_specifiers: list[nox._parametrize.Param] = [
nox.param("all", id="all"),
nox.param("with code coverage", id="cov"),
nox.param("skip slow tests", id="skipslow"),
nox.param("lowest-direct", id="lowest-direct"),
]


@nox.session(python=supported_python_versions)
@nox.parametrize("test_specifier", test_specifiers)
Copy link
Member Author

@namurphy namurphy May 10, 2024

Choose a reason for hiding this comment

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

📝 One neat thing about nox is that we can parametrize test sessions with an API that is very close to @pytest.mark.parametrize.

🤔 The id fields here make it so that test_specifier= doesn't show up in the list of parametrized nox sessions.

🌠 Parametrizing it this way also makes it so that we only need a single tests function for running pytest.


supported_python_versions = ("3.10", "3.11", "3.12")
supported_python_versions: tuple[str, ...] = ("3.10", "3.11", "3.12")
Copy link
Member Author

@namurphy namurphy May 10, 2024

Choose a reason for hiding this comment

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

🤔 I was debating about whether the type hint annotations were necessary in this file, but decided that they were since the annotations will help IDEs like PyCharm to highlight configuration problems while we're still making edits to a file.

Comment on lines +27 to +31
current_python = f"{sys.version_info.major}.{sys.version_info.minor}"

nox.options.sessions: list[str] = [f"tests-{current_python}(skipslow)"]
nox.options.default_venv_backend = "uv|virtualenv"

Copy link
Member Author

Choose a reason for hiding this comment

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

🛗 Moved without changes.

]

category_flags = {
category_flags: dict[str, tuple[str, ...]] = {
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 An annotation of tuple[str] would indicate that the tuple must contain exactly one string, whereas tuple[str, ...] indicates any number of strings. The ... is not necessary for lists, since lists are mutable.

@namurphy namurphy marked this pull request as ready for review May 10, 2024 21:13
@namurphy namurphy requested a review from a team as a code owner May 10, 2024 21:13
@namurphy namurphy requested review from ejohnson-96 and pheuer and removed request for a team May 10, 2024 21:13
Copy link
Contributor

@ejohnson-96 ejohnson-96 left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ejohnson-96 ejohnson-96 left a comment

Choose a reason for hiding this comment

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

Documentation is failing

@namurphy
Copy link
Member Author

I ran the failing check again since it looked like an intermittent failure (I think it was due to problems getting dependencies or something), so I'll go ahead and merge it.

@ejohnson-96 — Thank you for the review, and also for the wonderful dissertation defense! 🎆

@namurphy namurphy merged commit c84b867 into PlasmaPy:main May 13, 2024
15 checks passed
@namurphy namurphy deleted the nox-pytest branch May 13, 2024 15:21
@namurphy namurphy added the nox Related to the nox automation software label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Related to continuous integration nox Related to the nox automation software testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants