-
Notifications
You must be signed in to change notification settings - Fork 306
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
category_version_resolution: list[tuple[str, str, str]] = [ | ||
("tests", version, resolution) | ||
for version in supported_python_versions | ||
for resolution in ("highest", "lowest-direct") |
There was a problem hiding this comment.
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).
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) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
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" | ||
|
There was a problem hiding this comment.
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, ...]] = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is failing
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! 🎆 |
This PR adds a
tests
🧪 session tonoxfile.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:all
)skipslow
)cov
)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.