diff --git a/testsuite/MDAnalysisTests/converters/test_rdkit.py b/testsuite/MDAnalysisTests/converters/test_rdkit.py index 3af7f78e98d..8eee119c51e 100644 --- a/testsuite/MDAnalysisTests/converters/test_rdkit.py +++ b/testsuite/MDAnalysisTests/converters/test_rdkit.py @@ -23,6 +23,7 @@ import copy from io import StringIO +import warnings import pytest import MDAnalysis as mda from MDAnalysis.topology.guessers import guess_atom_element @@ -255,9 +256,9 @@ def test_error_no_hydrogen(self, uo2): uo2.atoms.convert_to("RDKIT") def test_error_no_hydrogen_implicit(self, uo2): - with pytest.warns(None) as record: + with warnings.catch_warnings(): + warnings.simplefilter("error") uo2.atoms.convert_to.rdkit(NoImplicit=False) - assert len(record) == 0 def test_warning_no_hydrogen_force(self, uo2): with pytest.warns(UserWarning, @@ -396,11 +397,9 @@ def test_sanitize_fail_warning(self): u = mda.Universe(mol) with pytest.warns(UserWarning, match="Could not sanitize molecule"): u.atoms.convert_to.rdkit(NoImplicit=False) - with pytest.warns(None) as record: + with warnings.catch_warnings(): + warnings.filterwarnings("error", "Could not sanitize molecule") u.atoms.convert_to.rdkit() - if record: - assert all("Could not sanitize molecule" not in str(w.message) - for w in record.list) @requires_rdkit diff --git a/testsuite/MDAnalysisTests/lib/test_util.py b/testsuite/MDAnalysisTests/lib/test_util.py index f59740a7f2f..d6dc2f42420 100644 --- a/testsuite/MDAnalysisTests/lib/test_util.py +++ b/testsuite/MDAnalysisTests/lib/test_util.py @@ -1535,7 +1535,7 @@ def myfunc(): class TestWarnIfNotUnique(object): - """Tests concerning the decorator @warn_if_not_uniue + """Tests concerning the decorator @warn_if_not_unique """ def warn_msg(self, func, group, group_name): @@ -1569,10 +1569,11 @@ def outer(group): # Check that no warning is raised for a unique group: assert atoms.isunique - with pytest.warns(None) as w: + + with warnings.catch_warnings(): + warnings.simplefilter("error") x = outer(atoms) assert x == 0 - assert not w.list # Check that a warning is raised for a group with duplicates: ag = atoms + atoms[0] @@ -1700,9 +1701,9 @@ def func(group): with warnings.catch_warnings(record=True) as record: warnings.resetwarnings() warnings.filterwarnings("ignore", category=UserWarning) - with pytest.warns(None) as w: + with warnings.catch_warnings(): + warnings.simplefilter("error") func(atoms) - assert not w.list assert len(record) == 0