diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index 8810ca30551..4dc22b11639 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -14,7 +14,7 @@ from pymatgen.alchemy.transmuters import StandardTransmuter from pymatgen.analysis.structure_matcher import StructureMatcher from pymatgen.core import Lattice, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest class TestContainsSpecieFilter: @@ -52,7 +52,7 @@ def test_as_from_dict(self): assert isinstance(ContainsSpecieFilter.from_dict(dct), ContainsSpecieFilter) -class TestSpecieProximityFilter: +class TestSpecieProximityFilter(PymatgenTest): def test_filter(self): struct = self.get_structure("Li10GeP2S12") sf = SpecieProximityFilter({"Li": 1}) @@ -70,8 +70,8 @@ def test_as_from_dict(self): assert isinstance(SpecieProximityFilter.from_dict(dct), SpecieProximityFilter) -class TestRemoveDuplicatesFilter(TestCase): - def setUp(self): +class TestRemoveDuplicatesFilter: + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 2569b7ec46c..51c76bcef1e 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -22,7 +22,7 @@ class TestTransformedStructure: - def setUp(self): + def setup_method(self): structure = PymatgenTest.get_structure("LiFePO4") self.structure = structure trafos = [SubstitutionTransformation({"Li": "Na"})] diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index 3d0f73e58ed..90ec2df89d1 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -1,6 +1,5 @@ from __future__ import annotations -import warnings from shutil import which import numpy as np @@ -10,16 +9,13 @@ from pytest import approx from pymatgen.command_line.bader_caller import BaderAnalysis, bader_analysis_from_path -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/command_line/bader" @pytest.mark.skipif(not which("bader"), reason="bader executable not present") -class TestBaderAnalysis: - def setUp(self): - warnings.catch_warnings() - +class TestBaderAnalysis(PymatgenTest): def test_init(self): # test with reference file analysis = BaderAnalysis( diff --git a/tests/command_line/test_critic2_caller.py b/tests/command_line/test_critic2_caller.py index 430b052d4bf..55346936b92 100644 --- a/tests/command_line/test_critic2_caller.py +++ b/tests/command_line/test_critic2_caller.py @@ -1,7 +1,6 @@ from __future__ import annotations from shutil import which -from unittest import TestCase import pytest from pytest import approx @@ -75,8 +74,8 @@ def test_from_structure(self): assert "ERROR : load int.CHGCAR id chg_int zpsp Mo 6 S 6" in c2c._input_script -class TestCritic2Analysis(TestCase): - def setUp(self): +class TestCritic2Analysis: + def setup_method(self): stdout_file = f"{TEST_DIR}/MoS2_critic2_stdout.txt" stdout_file_new_format = f"{TEST_DIR}/MoS2_critic2_stdout_new_format.txt" with open(stdout_file) as file: diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index b55ff9c2fea..aa3cebff4a3 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -11,14 +11,14 @@ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.transformations.site_transformations import RemoveSitesTransformation from pymatgen.transformations.standard_transformations import SubstitutionTransformation -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest ENUM_CMD = which("enum.x") or which("multienum.x") MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py") @pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.") -class TestEnumlibAdaptor: +class TestEnumlibAdaptor(PymatgenTest): def test_init(self): struct = self.get_structure("LiFePO4") sub_trans = SubstitutionTransformation({"Li": {"Li": 0.5}}) diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 18c3f05c268..4dc27857afa 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -9,7 +9,6 @@ import os import sys from shutil import which -from unittest import TestCase import numpy as np import pytest @@ -106,8 +105,8 @@ def test_decimal(self): caller.run(buckingham_input) -class TestGulpIO(TestCase): - def setUp(self): +class TestGulpIO: + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18") self.gio = GulpIO() @@ -276,8 +275,8 @@ def test_tersoff_input(self): self.gio.tersoff_input(self.structure) -class TestGlobalFunctions(TestCase): - def setUp(self): +class TestGlobalFunctions: + def setup_method(self): mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg", "O"] * 4 mgo_frac_cord = [ @@ -327,8 +326,8 @@ def test_get_energy_relax_structure_buckingham(self): assert site_len == len(self.mgo_uc) -class TestBuckinghamPotentialLewis(TestCase): - def setUp(self): +class TestBuckinghamPotentialLewis: + def setup_method(self): self.bpl = BuckinghamPotential("lewis") def test_existing_element(self): @@ -354,8 +353,8 @@ def test_spring(self): assert self.bpl.spring_dict["O"] != "" -class TestBuckinghamPotentialBush(TestCase): - def setUp(self): +class TestBuckinghamPotentialBush: + def setup_method(self): self.bpb = BuckinghamPotential("bush") def test_existing_element(self): diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index b214f42b262..6bc185443f2 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -7,7 +7,7 @@ from pymatgen.command_line.mcsqs_caller import run_mcsqs from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Handong Ling, Rachel Woods-Robinson" __maintainer__ = "Handong Ling, Rachel Woods-Robinson" @@ -18,7 +18,7 @@ @pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present") -class TestMcsqsCaller: +class TestMcsqsCaller(PymatgenTest): def setUp(self): self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") @@ -103,5 +103,5 @@ def test_mcsqs_caller_runtime_error(self): struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}}) struct.replace_species({"Pb": {"Ti": 0.2, "Pb": 0.8}}) struct.replace_species({"O": {"F": 0.8, "O": 0.2}}) - with pytest.raises(RuntimeError, match="mcsqs exited before timeout reached"): + with pytest.raises(RuntimeError, match="mcsqs did not generate output files"): run_mcsqs(struct, {2: 6, 3: 4}, 10, 0.000001) diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index cc8fb7c254c..6021f65a366 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -16,7 +16,7 @@ @pytest.mark.skipif(not which("vampire-serial"), reason="vampire executable not present") class TestVampireCaller: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") cls.compounds = [cls.Mn3Al]