Skip to content

Commit

Permalink
sets debug level to ensure do_assert returns expression; changes skip…
Browse files Browse the repository at this point in the history
… condition to __debug__
  • Loading branch information
Tom O'Hara committed Sep 24, 2023
1 parent a61afd8 commit c1aa76b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mezcla/tests/test_unittest_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c1aa76b

Please sign in to comment.