Skip to content

Assertions are not tested when testing system exit

Here is a modification of test_unit_tx.py that still pass, but should not (I added an assert False):

# compute_amounts()
def test_compute_amounts_errors(capsys):
    trials = (((0.0031, 1), 314),)
    for trial in trials:
        # check program exit on error
        with pytest.raises(SystemExit) as pytest_exit:
            # read output to check error.
            tx.compute_amounts(
                trial[0],
                trial[1],
            )
            expected_error = "Error: amount {0} is too low.".format(trial[0][0])
            assert capsys.readouterr() == expected_error
            # Assert False to show there is a bug in this kind of context
            assert False
        assert pytest_exit.type == SystemExit

It means that basically, all assertions in a context like with pytest.raises(SystemExit) as pytest_exit: are not tested if ther is a message_exit(), because the function exits first.

I don't know how to solve it for now.

Edited by Moul
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information