From 23e62f101ea1b8da2f677c00630aaa138bb86043 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 5 Aug 2024 23:41:27 +0000 Subject: [PATCH] make warning assertion more robust Signed-off-by: Jinzhe Zeng --- tests/analysis/elasticity/test_elastic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 4fe8ecdc5da..10f2b9c2296 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -182,7 +182,7 @@ def test_new(self): UserWarning, match="Input elastic tensor does not satisfy standard Voigt symmetries" ) as warns: ElasticTensor(non_symm) - assert len(warns) == 1 + assert sum("Input elastic tensor does not satisfy standard Voigt symmetries" in str(warn) for warn in warns) == 1 bad_tensor1 = np.zeros((3, 3, 3)) bad_tensor2 = np.zeros((3, 3, 3, 2)) @@ -220,7 +220,8 @@ def test_from_independent_strains(self): stresses = self.toec_dict["stresses"] with pytest.warns(UserWarning, match="No eq state found, returning zero voigt stress") as warns: et = ElasticTensor.from_independent_strains(strains, stresses) - assert len(warns) == 2 + assert sum("No eq state found" in str(warn) for warn in warns) == 1 + assert sum("Extra strain states in strain-" in str(warn) for warn in warns) == 1 assert_allclose(et.voigt, self.toec_dict["C2_raw"], atol=1e1) def test_energy_density(self):