Skip to content

Conversation

@mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Dec 8, 2025

The primary change in this PR is to do better test skipping if optional dependencies or executables are not available.

It also applies a few basic lint fixes discovered (and sometimes auto-fixed) with ruff check. So only a small subset of these are addressed in this PR:

$ uvx ruff check --statistics
324     F841    [-] unused-variable
239	F401	[-] unused-import
168	E722	[ ] bare-except
 27	E402	[ ] module-import-not-at-top-of-file
 21	E721	[ ] type-comparison
 17	E712	[ ] true-false-comparison
 17	F821	[ ] undefined-name
 16	F523	[-] string-dot-format-extra-positional-arguments
 16	F811	[-] redefined-while-unused
 15	E731	[ ] lambda-assignment
 14	F541	[*] f-string-missing-placeholders
 10	E741	[ ] ambiguous-variable-name
 10	F403	[ ] undefined-local-with-import-star
  5	E713	[*] not-in-test
  4	E711	[ ] none-comparison
  3	    	[ ] invalid-syntax
  2	E401	[*] multiple-imports-on-one-line
  1	E703	[*] useless-semicolon
  1	F402	[ ] import-shadowed-by-loop-var
  1	F602	[ ] multi-value-repeated-key-variable
Found 911 errors.
[*] 305 fixable with the `--fix` option (317 hidden fixes can be enabled with the `--unsafe-fixes` option).

where after this PR the remaining are:

$ uvx ruff check --statistics
301     F841    [ ] unused-variable
209	F401	[-] unused-import
129	E722	[ ] bare-except
 27	E402	[ ] module-import-not-at-top-of-file
 21	E721	[ ] type-comparison
 17	E712	[ ] true-false-comparison
 15	E731	[ ] lambda-assignment
 14	F821	[ ] undefined-name
 10	E741	[ ] ambiguous-variable-name
 10	F403	[ ] undefined-local-with-import-star
  8	F811	[ ] redefined-while-unused
  1	F602	[ ] multi-value-repeated-key-variable
Found 762 errors.
[*] 187 fixable with the `--fix` option (333 hidden fixes can be enabled with the `--unsafe-fixes` option).

(And I don't think all of these need to be addressed and can be ignored).

@coveralls
Copy link

Coverage Status

coverage: 77.921% (+0.05%) from 77.871%
when pulling b991997 on mwtoews:pytest-skip-and-basic-lints
into 5dd3c78 on pypest:develop.

@briochh
Copy link
Collaborator

briochh commented Dec 9, 2025

thanks for this @mwtoews. The codebase could defo benefit from a clean up, I am wondering how tolerant we want to be of failed imports and missing binaries though? Those red 'x's are a pretty strong motivator to fix broken links between packages and dependancies.

Copy link
Collaborator

@briochh briochh left a comment

Choose a reason for hiding this comment

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

@mwtoews, thanks for these improves. See comments around flopy and ppu import fail skips... think we might be better off with a non-skipping option in most cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this notebook wrapper is no longer hit -- at some point, we should check and remove,


def dsi_freyberg(tmp_d,transforms=None,tag=""):
if not ies_exe_path:
pytest.skip("missing ies_exe_path")
Copy link
Collaborator

Choose a reason for hiding this comment

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

assume we will throw a fail elsewhere in the CI if bins are missing -- might be worth checking this.


def gpr_compare_invest():
if not mou_exe_path:
pytest.skip("missing mou_exe_path")
Copy link
Collaborator

Choose a reason for hiding this comment

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

These "invest" funcs shouldn't be collected by pytest in the first place, so the "skip" probs ineffective.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is also mostly legacy func testing -- at some point we should check and remove

# import sys
# sys.path.insert(0, os.path.join("..", "..", "pypestutils"))
import pypestutils as ppu
ppu = pytest.importorskip("pypestutils")
Copy link
Collaborator

Choose a reason for hiding this comment

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

we probably don't want to be skipping this test if import fails.

Currently, there is the pyemu geostats interp fallback if ppu is not available (though this may be deprecated in the future if we want to lean more on ppu)

So here, I think we either want to raise if import fails or continue (which would mean that we are testing the pyemu fallback).



def mf6_freyberg_da_test(tmp_path):
flopy = pytest.importorskip("flopy")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for these we can just do a straight import flopy. flopy should be defined as a testing dependency (only) so if you are running these tests you do need flopy so these would be better to raise rather than skip?

# import sys
# sys.path.insert(0,os.path.join("..","..","pypestutils"))
import pypestutils as ppu
ppu = pytest.importorskip("pypestutils")
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto above, either we should be raising here if ppu absent or (for now) continuing and allowing pyemu geostationary fallback

Copy link
Collaborator

Choose a reason for hiding this comment

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

generally for the tests in here we rely on flopy (which should be a testing-only dependency for pyemu). So I think ok to raise rather than skip if flopy import fails. For dealing with ppu import fails at the moment (while we still have the pyemu geostat fallback) I think we can continue but in the future we could look to retire the pyemu fallback and require ppu [perhaps we can set up a discussion on this?], in which case raising on ppu import fails would be appropriate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

same as in pst_from_tests regarding flopy and ppu imports -- maybe raising is preferable to skipping?

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.

3 participants