Skip to content

Commit

Permalink
Update testing for exit code changes
Browse files Browse the repository at this point in the history
The testing needs to be updated now that `example.main()` only returns a
`None` and error exits are done by directly calling `sys.exit()`.
  • Loading branch information
mcdonnnj committed Jul 14, 2021
1 parent 29ade6f commit 015d47e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,26 @@ def test_log_levels(level):
assert (
logging.root.hasHandlers() is False
), "root logger should not have handlers yet"
return_code = example.example.main()
return_code = None
try:
example.example.main()
except SystemExit as sys_exit:
return_code = sys_exit.code
assert return_code is None, "main() should return success"
assert (
logging.root.hasHandlers() is True
), "root logger should now have a handler"
assert return_code == 0, "main() should return success (0)"


def test_bad_log_level():
"""Validate bad log-level argument returns error."""
with patch.object(sys, "argv", ["bogus", "--log-level=emergency", "1", "1"]):
return_code = example.example.main()
assert return_code == 1, "main() should return failure"
return_code = None
try:
example.example.main()
except SystemExit as sys_exit:
return_code = sys_exit.code
assert return_code == 1, "main() should exit with error"


@pytest.mark.parametrize("dividend, divisor, quotient", div_params)
Expand Down Expand Up @@ -124,5 +132,9 @@ def test_zero_division():
def test_zero_divisor_argument():
"""Verify that a divisor of zero is handled as expected."""
with patch.object(sys, "argv", ["bogus", "1", "0"]):
return_code = example.example.main()
return_code = None
try:
example.example.main()
except SystemExit as sys_exit:
return_code = sys_exit.code
assert return_code == 1, "main() should exit with error"

0 comments on commit 015d47e

Please sign in to comment.