Skip to content

Commit

Permalink
Replace deprecated pytest.warns(None) (MDAnalysis#3952)
Browse files Browse the repository at this point in the history
* Replace deprecated pytest.warns(None)
  • Loading branch information
IAlibay authored Dec 9, 2022
1 parent 10b0a91 commit 4c9108b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 5 additions & 6 deletions testsuite/MDAnalysisTests/converters/test_rdkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions testsuite/MDAnalysisTests/lib/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 4c9108b

Please sign in to comment.