From 51a1e7931f82126e3c767b1ae19e6cfdb98e478a Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Sun, 16 Jun 2024 23:43:36 -0700 Subject: [PATCH] improved warning management - ignore some warnings in pytest - check for some gromacs.UsageWarning explicitly --- pyproject.toml | 11 +++++++++-- tests/test_setup.py | 46 ++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0a07a2df..13e99342 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,13 @@ rmprefix = "release-" file = "gromacs/_version.py" - [tool.black] -extend-exclude = "tests/(test_core|fileformats/test_convert)\\.py" \ No newline at end of file +extend-exclude = "tests/(test_core|fileformats/test_convert)\\.py" + + +[tool.pytest.ini_options] +filterwarnings = [ + "ignore::gromacs.AutoCorrectionWarning", + "ignore::gromacs.LowAccuracyWarning", + "ignore::numkit.LowAccuracyWarning", + ] diff --git a/tests/test_setup.py b/tests/test_setup.py index ba2cfbd6..dbf3828b 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -61,13 +61,17 @@ def energy_minimize(solvate, low_performance): TMPDIR, solvate_args = solvate nt = 2 if low_performance else 0 with TMPDIR.as_cwd(): - em_args = gromacs.setup.energy_minimize( - mdrun_args={"nt": nt}, - integrator="steep", - emtol=5000, - maxwarn=1, - **solvate_args, - ) + with pytest.warns( + gromacs.UsageWarning, + match="Unprocessed mdp option are interpreted as options for grompp", + ): + em_args = gromacs.setup.energy_minimize( + mdrun_args={"nt": nt}, + integrator="steep", + emtol=5000, + maxwarn=1, + **solvate_args, + ) return TMPDIR, em_args @@ -106,18 +110,22 @@ def test_energy_minimize_custom_mdp( TMPDIR, solvate_args = solvate nt = 2 if low_performance else 0 with TMPDIR.as_cwd(): - try: - em_args = gromacs.setup.energy_minimize( - mdrun_args={"nt": nt}, mdp=mdp, emtol=5000, **solvate_args - ) - except gromacs.exceptions.GromacsError as err: - # sometimes the em does not converge at all, e.g. 5.02988e+04 on atom 3277; - # (happens on Travis Linux with Gromacs 4.6.5 but not locally or on Travis OSX) so we - # re-run with a ridiculous tolerance so that we can at least test that the whole - # function can run to completion - em_args = gromacs.setup.energy_minimize( - mdrun_args={"nt": nt}, mdp=mdp, emtol=6e4, **solvate_args - ) + with pytest.warns( + gromacs.UsageWarning, + match="Unprocessed mdp option are interpreted as options for grompp", + ): + try: + em_args = gromacs.setup.energy_minimize( + mdrun_args={"nt": nt}, mdp=mdp, emtol=5000, **solvate_args + ) + except gromacs.exceptions.GromacsError as err: + # sometimes the em does not converge at all, e.g. 5.02988e+04 on atom 3277; + # (happens on Travis Linux with Gromacs 4.6.5 but not locally or on Travis OSX) so we + # re-run with a ridiculous tolerance so that we can at least test that the whole + # function can run to completion + em_args = gromacs.setup.energy_minimize( + mdrun_args={"nt": nt}, mdp=mdp, emtol=6e4, **solvate_args + ) assert os.path.exists(em_args["struct"]) assert os.path.exists(em_args["top"]) assert em_args["mainselection"] == '"Protein"'