Pytest integrated#3331
Conversation
matching either to a file named `test_foo.py`.
Native configuration is x86_64-pc-linux-gnu
=== tests ===
Schedule of variations:
unix
Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
=== Summary === to in CMakeLists.txt
so that the `input` directory is found.
so that the `test` directory is found.
so that the `data` directory is found.
Fails due to missing file `grid.fci.nc`.
Change directory to exe location prior to attempting to run it.
Change directory to exe location prior to attempting to run it.
Change directory to exe location prior to attempting to run it.
3e91b3a to
7f920ac
Compare
dschwoerer
left a comment
There was a problem hiding this comment.
It seems one of the MMS tests is missing. That certainly needs fixing.
I find it also increadibly hard to review, as in some case the rename from runtest to test_* is not rendered correctly on github. In some cases this seems to be done such that git itself is not aware of the the rename, e.g. test-fci-mpi/runtest.
This makes it even harder to figure out what was changed, as you clearly did not write the whole test new.
I have reviewed test-fci-mpi/runtest more carefully, and it is doing only part what is in next. It is skipping the iteration over the different test cases:
https://github.com/boutproject/BOUT-dev/blob/next/tests/integrated/test-fci-mpi/runtest#L49
Also, it would only output the errors after the assert:
So this is never printed.
| # Requires: netcdf | ||
| # Requires: not metric_3d | ||
| # Cores: 4 | ||
|
|
There was a problem hiding this comment.
I doubt the current test system still parses and process them, so the can be removed?
|
I forgot - the new pytest is much faster, which is nice, but I am wondering this comes from skipping tests. |
(accidentally re-added when merging in `next`).
…grid_laplace to prevent spurious test failures due to unused options.
ZedThree
left a comment
There was a problem hiding this comment.
There's a few things that haven't been ported exactly right, and there's still quite a few patterns that I would like to update, but they could be done in a separate PR so we can get the bulk of the changes in sooner. Maybe just leave all the "could be..." for now, and concentrate on fixing the other comments
I noticed some particular patterns that we could improve upon in a second PR:
Could have a helper function to simplify this pattern:
s, out = launch_safe(...)
with open("run.log", "w") as f:
f.write(out)We have quite a few tests that do something vaguely like this:
# some setup
launch(cmd, ...)
success = True
for v in vars:
r = collect(v)
success &= r < tol
assert successwhere we run an executable, and want to check all the variables before failing, rather than just failing on the first bad one.
This pattern is maybe best transformed into a fixture, and then the test is parameterised over the variables:
@fixture(scope="module")
def fixture():
# some setup
launch(cmd, ...)
@parametrize(variables)
def test(variables):
assert_allclose(r, expected)then we only actually run the code once, but can parallelise over the variables. I think there's a way to parameterise fixtures too, so this could also run once e.g. per nproc.
| # Install the core requirements into the same venv | ||
| uv pip install -r requirements.txt |
There was a problem hiding this comment.
Orthogonal PR -> this file should be merged into pyprojects.toml
| if fe.getLocation() == fc.getLocation(): | ||
| print("The loaded field should not be at CELL_CENTRE") | ||
| fail = 1 |
There was a problem hiding this comment.
This could be
| if fe.getLocation() == fc.getLocation(): | |
| print("The loaded field should not be at CELL_CENTRE") | |
| fail = 1 | |
| assert fe.getLocation() != fc.getLocation(), "The loaded field should not be at CELL_CENTRE" |
| if compare(fc, f) > 1e-3: | ||
| print("Something is wrong. Maybe interpolation is broken") | ||
| fail = 1 |
There was a problem hiding this comment.
These could also be
| if compare(fc, f) > 1e-3: | |
| print("Something is wrong. Maybe interpolation is broken") | |
| fail = 1 | |
| assert compare(fc, f) <= 1e-3, "Maybe interpolation is broken" |
| # Requires: netcdf | ||
| # Cores: 4 |
There was a problem hiding this comment.
We can delete all of these # Requires and # Cores comments now too
| for data_dir, stop_file in zip(data_dirs, stop_files): | ||
| for check, expected in zip(check_values, expected_steps): |
There was a problem hiding this comment.
Not sure this has been converted?
| pytest = [ | ||
| "pytest~=8.4", | ||
| "pytest-xdist~=3.8", | ||
| ] |
There was a problem hiding this comment.
Can we add the other test dependencies here too? numpy, scipy, zoidberg, etc? And perhaps rename:
| pytest = [ | |
| "pytest~=8.4", | |
| "pytest-xdist~=3.8", | |
| ] | |
| test = [ | |
| "pytest~=8.4", | |
| "pytest-xdist~=3.8", | |
| ] |
| return False | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("shift_type, variable", list(zip(shift_types, variables))) |
There was a problem hiding this comment.
I think this is wrong? This runs the following cases:
"shifted"+("ddy", "ddy_check")"shiftedinterp"+("ddy2", "ddy_check")
but we want to run once for each of the shift_types, and check all of variables for each run
|
I think this should be merged quickly, as it it seems like a great improvement, as it makes the tests faster. I am however worried that there are regressions. @ZedThree did you compare test by test, to make sure this (still) matches what is in next? It is a bit difficult to get a feeling of the state of this, with so little comments from @tomc271 I would be willing to review at least part of this, but only if you think this is close to being merged, so the review does not get outdated. |
|
@dschwoerer Yeah, I went through one by one, comparing the @tomc271 Can you comment when you've fixed |
No description provided.