-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
Pytest for unit testing #3857
Pytest for unit testing #3857
Conversation
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
Reason why tests are failing is because def test_function(arg):
return arg + arg using:
insted of
But assertion fails (in unittest and pytest):
Maybe if we define |
One easy fix is to rename functions like Edit:
I can still try solving this with them but that would mean completely getting rid of test_function type functions.
|
Does renaming them from |
yes we can also do that. |
Signed-off-by: Pradyot Ranjan <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #3857 +/- ##
========================================
Coverage 99.60% 99.60%
========================================
Files 259 259
Lines 21347 21347
========================================
Hits 21263 21263
Misses 84 84 ☔ View full report in Codecov by Sentry. |
Why are the CI tasks failing? |
It's probably coming from Matplotlib opening too many figures/plots when running the tests. We should close them after they are opened, I guess. There might be a few other failures due to differences in how Also, according to #3857 (comment) that the coverage is 19.40%, which means that the coverage percentage is not being reported correctly. We would need to add pytest-cov and configure it with the unit tests, as noted by @Saransh-cpp in #3617 (comment). |
These are mostly the failures we have to deal with :
I don't understand failures with |
I think the Re: the Matplotlib error, I'm not sure either. It looks like an unrelated error and is probably coming from |
I did encounter
we can do: geo_latex = fr"\quad {rng_min} < {name} < {rng_max}" Can we do that without any breaking changes? |
I think so, yes. To verify that the change doesn't break anything, you can try out the latexify notebook and ensure that the outputs remain the same |
Signed-off-by: Pradyot Ranjan <[email protected]>
We should have more number of checks with this. |
How to get covergae report?
but it's unable to find tests.
only gives me 20% coverage. What am I doing wrong? |
The command should be:
More on coverage with pytest here - https://learn.scientific-python.org/development/guides/coverage/ |
Oh wrong command. This was embarrassing. 🙃 |
Merge changes from develop
I am going to merge develop into this to see if the test failures happen again |
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.
Minor stuff
tests/unit/test_expression_tree/test_operations/test_evaluate_python.py
Outdated
Show resolved
Hide resolved
Yeah we should just have a link to the main docs page instead of a versioned one. |
To fix the failing Windows tests, let's use the Agg backend for Matplotlib to not open up a GUI. We can either set the from matplotlib import use
use("Agg") wherever we have Edit: I noticed that we set |
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
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.
This looks quite good on my end, and I have just a few additional comments. Let's merge after either @kratman or @Saransh-cpp can review again.
I noticed that we set MPLBACKEND to "Template" in run-tests.py, which would have set that backend back again when running the tests. Let's switch that environment variable to Agg as well.
This got lost in the conversation, probably – could you please do this too?
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 don't see any major issues here, however @agriyakhetarpal has an open discussion, so lets make sure to resolve that before we merge the changes from @prady0t
Almost all good from my end, just the comment about removing the "Template" Matplotlib backend from |
Signed-off-by: Pradyot Ranjan <[email protected]>
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.
Nice work @prady0t, everything looks nice to me.
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.
Thanks for all the fixes, @prady0t – let's merge when all of the unit tests pass (which will be when all of the integration tests pass, they run in alphabetical order)
Just few more months and i'll speed up the integration tests as well. 😉 |
* Using pytest to run tests Signed-off-by: Pradyot Ranjan <[email protected]> * Adjusting noxfile to account for both pytest and unittest Signed-off-by: Pradyot Ranjan <[email protected]> * renamed 'args' argument functions Signed-off-by: Pradyot Ranjan <[email protected]> * added raw string Signed-off-by: Pradyot Ranjan <[email protected]> * style: pre-commit fixes * added raw string again Signed-off-by: Pradyot Ranjan <[email protected]> * added pytest-cov support and added raw strings Signed-off-by: Pradyot Ranjan <[email protected]> * added [dev] to script session Signed-off-by: Pradyot Ranjan <[email protected]> * Changes for failing test cases on windows Signed-off-by: Pradyot Ranjan <[email protected]> * Moved repetitive functions to shared.py Signed-off-by: Pradyot Ranjan <[email protected]> * style: pre-commit fixes * Changing MPLBACKEND value to Agg Signed-off-by: Pradyot Ranjan <[email protected]> --------- Signed-off-by: Pradyot Ranjan <[email protected]> Co-authored-by: Pradyot Ranjan <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric G. Kratz <[email protected]>
Description
Still a WIP.
Since most of the integration tests were failing, they need to be rewritten completely before we can switch to pytest. For now we are using pytest just for unit tests. We still reduce testing time while running
nox
by a considerable factor.Addresses a part of #3617
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.
Key checklist:
$ pre-commit run
(or$ nox -s pre-commit
) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)$ python run-tests.py --all
(or$ nox -s tests
)$ python run-tests.py --doctest
(or$ nox -s doctests
)You can run integration tests, unit tests, and doctests together at once, using
$ python run-tests.py --quick
(or$ nox -s quick
).Further checks: