Repository navigation
Move reused data to pytest fixtures in test_grdtrack.py - #1353
Conversation
|
Thanks, @willschlitzer! I would be interested in whether adding the csvfile and ncfile as fixtures speeds it up even more (used 3 times each): |
Big time savings! 667 ms vs 411 ms, so with all of the fixtures this cuts down the test time by half! Side note: Is there any reason we use |
weiji14
left a comment
There was a problem hiding this comment.
Thanks @willschlitzer!
Side note: Is there any reason we use @pytest.fixture instead of creating global variables in the script?
Good question. I think pytest fixtures (https://docs.pytest.org/en/latest/explanation/fixtures.html) are more explicit than global variables. Other than that, either fixtures or global variables would technically work for test_grdtrack.py. However, if we're going to parallelize tests (using something like pytest-xdist) at some point, then fixtures would probably be preferrable.
I'm wondering if there are global pytest fixtures. After a quick search, I find this (https://betterprogramming.pub/understand-5-scopes-of-pytest-fixtures-1b607b5c19ed). It seems a |
Yes there are session, function, class, module and package scoped fixtures (see https://docs.pytest.org/en/latest/reference/fixtures.html#reference-fixtures). I'd prefer to keep the fixtures used by a test in the same test_*.py file and not to use a |
Yes, I agree. When I worked on the PR #1359, I felt that the variable |
Five test functions in
test_grdtrack.pyuse a dataframe fromload_ocean_ridge_points()and called it inside the test functions. This pull requests moves it tofixture_dataframe().Over five runs of
test_grdtrack.pyon my machine, the average time for the old tests was 906 ms and the new tests averaged 658 ms.Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash commands are:
/format: automatically format and lint the code/test-gmt-dev: run full tests on the latest GMT development version