From 9c1f087657026236e9f5430cd2afd7b9b0935792 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 17 Jan 2023 20:26:26 -0800 Subject: [PATCH 1/3] Resolve flake8 error by replacing `pytest.raises(Exception)` with `SystemError` --- tests/test_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_modules.py b/tests/test_modules.py index e11d68e78e..cb5affc36b 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -107,7 +107,7 @@ def test_def_submodule_failures(): sm_name_orig = sm.__name__ sm.__name__ = malformed_utf8 try: - with pytest.raises(Exception): + with pytest.raises(SystemError): # Seen with Python 3.9: SystemError: nameless module # But we do not want to exercise the internals of PyModule_GetName(), which could # change in future versions of Python, but a bad __name__ is very likely to cause From 49f258e04e4df654b9a12cdcd0a60eecd95f9f7d Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 17 Jan 2023 21:04:16 -0800 Subject: [PATCH 2/3] Also remove the obsolete comment. --- tests/test_modules.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_modules.py b/tests/test_modules.py index cb5affc36b..433094f27d 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -108,10 +108,6 @@ def test_def_submodule_failures(): sm.__name__ = malformed_utf8 try: with pytest.raises(SystemError): - # Seen with Python 3.9: SystemError: nameless module - # But we do not want to exercise the internals of PyModule_GetName(), which could - # change in future versions of Python, but a bad __name__ is very likely to cause - # some kind of failure indefinitely. m.def_submodule(sm, b"SubSubModuleName") finally: # Clean up to ensure nothing gets upset by a module with an invalid __name__. From f87da1bf48e937c76f941f23882cb09168642c42 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 18 Jan 2023 13:18:33 -0800 Subject: [PATCH 3/3] Tweak comment instead of removing it. --- tests/test_modules.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_modules.py b/tests/test_modules.py index 433094f27d..c3e8cea6e1 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -107,6 +107,9 @@ def test_def_submodule_failures(): sm_name_orig = sm.__name__ sm.__name__ = malformed_utf8 try: + # We want to assert that a bad __name__ causes some kind of failure, although we do not want to exercise + # the internals of PyModule_GetName(). Currently all supported Python versions raise SystemError. If that + # changes in future Python versions, simply add the new expected exception types here. with pytest.raises(SystemError): m.def_submodule(sm, b"SubSubModuleName") finally: