From c1aa76b426b282f1a0d3d2f23fd6651b981b01a3 Mon Sep 17 00:00:00 2001 From: Tom O'Hara Date: Sun, 24 Sep 2023 00:26:37 -0500 Subject: [PATCH] sets debug level to ensure do_assert returns expression; changes skip condition to __debug__ --- mezcla/tests/test_unittest_wrapper.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mezcla/tests/test_unittest_wrapper.py b/mezcla/tests/test_unittest_wrapper.py index 5c149868..0c4486e4 100644 --- a/mezcla/tests/test_unittest_wrapper.py +++ b/mezcla/tests/test_unittest_wrapper.py @@ -55,25 +55,33 @@ class TestIt2: """Class for API usage""" - @pytest.mark.skipif(not debug.debugging(1), reason="Must be debugging") + @pytest.mark.skipif(not __debug__, reason="Must be under __debug__") ## TODO: ## @pytest_fixture_wrapper ## @trap_exception def test_do_assert(self, capsys): """Ensure do_assert identifies failing line""" debug.trace(4, f"TestIt.test_do_assert({capsys}); self={self}") - # + + # Get instance for test class + # TODO3: use TestWrapper() instead of SubTestIt() class SubTestIt(TestWrapper): """Embedded test suite""" pass # - sti = SubTestIt() + sti = SubTestIt() + + # Make assertion, ensuring debugging level set at minimum required (2) captured_trace = "" message = "Good math" + old_debug_level = debug.get_level() try: + debug.set_level(debug.TL.DEFAULT) sti.do_assert(2 + 2 == 5, message) # Orwell's condition except AssertionError: pass + finally: + debug.set_level(old_debug_level) captured_trace = capsys.readouterr().err debug.trace_expr(5, captured_trace)