Skip to content

Pytest integrated#3331

Open
tomc271 wants to merge 222 commits into
nextfrom
pytest-integrated
Open

Pytest integrated#3331
tomc271 wants to merge 222 commits into
nextfrom
pytest-integrated

Conversation

@tomc271

@tomc271 tomc271 commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread tests/run_integrated_tests.sh Outdated
Comment thread tests/run_integrated_tests.sh Outdated
Comment thread pyproject.toml
Comment thread CMakeLists.txt Outdated
Comment thread .ci_with_cmake.sh
Comment thread tests/integrated/test-boutpp/slicing/test_slicing.py Outdated
Comment thread tests/integrated/test-boutpp/slicing/test_slicing.py Outdated
Comment thread tests/integrated/test-boutpp/slicing/test_slicing.py Outdated
Comment thread tests/integrated/test-command-args/test_command_args.py Outdated
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.
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.
@tomc271 tomc271 force-pushed the pytest-integrated branch from 3e91b3a to 7f920ac Compare June 11, 2026 12:48

@dschwoerer dschwoerer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

assert success, "\nSome tests failed:"

So this is never printed.

# Requires: netcdf
# Requires: not metric_3d
# Cores: 4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I doubt the current test system still parses and process them, so the can be removed?

@dschwoerer

Copy link
Copy Markdown
Contributor

I forgot - the new pytest is much faster, which is nice, but I am wondering this comes from skipping tests.

@ZedThree ZedThree left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 success

where 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.

Comment thread manual/sphinx/developer_docs/contributing.rst Outdated
Comment on lines +170 to +171
# Install the core requirements into the same venv
uv pip install -r requirements.txt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Orthogonal PR -> this file should be merged into pyprojects.toml

Comment on lines +29 to +31
if fe.getLocation() == fc.getLocation():
print("The loaded field should not be at CELL_CENTRE")
fail = 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be

Suggested change
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"

Comment on lines +42 to +44
if compare(fc, f) > 1e-3:
print("Something is wrong. Maybe interpolation is broken")
fail = 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These could also be

Suggested change
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"

Comment on lines +7 to +8
# Requires: netcdf
# Cores: 4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can delete all of these # Requires and # Cores comments now too

Comment on lines +23 to +24
for data_dir, stop_file in zip(data_dirs, stop_files):
for check, expected in zip(check_values, expected_steps):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could be parameterised

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure this has been converted?

Comment thread pyproject.toml
Comment on lines +25 to +28
pytest = [
"pytest~=8.4",
"pytest-xdist~=3.8",
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add the other test dependencies here too? numpy, scipy, zoidberg, etc? And perhaps rename:

Suggested change
pytest = [
"pytest~=8.4",
"pytest-xdist~=3.8",
]
test = [
"pytest~=8.4",
"pytest-xdist~=3.8",
]

Comment thread .ci_with_cmake.sh
return False


@pytest.mark.parametrize("shift_type, variable", list(zip(shift_types, variables)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@dschwoerer

Copy link
Copy Markdown
Contributor

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.

@ZedThree

Copy link
Copy Markdown
Member

@dschwoerer Yeah, I went through one by one, comparing the runtest to the test_*.py. I think I only caught one actual regression (test_yupdown). It's probably wise to have a second set of eyes check things too.

@tomc271 Can you comment when you've fixed test_yupdown, and we'll merge then. Everything else can wait for a second PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants