DataMedSci / pymchelper

Python toolkit for SHIELD-HIT12A and FLUKA
http://datamedsci.github.io/pymchelper/
15 stars 7 forks source link

issues in testing #713

Closed nbassler closed 6 months ago

nbassler commented 7 months ago

e.g. the mcscripter test...

https://github.com/DataMedSci/pymchelper/blob/f39907b8dd6262fe6a1bf2f40ed170e4a5b7a5ee/tests/test_mcscripter.py#L54C1-L59C28

def test_call_cmd_no_option():
    """Description needed."""
    with pytest.raises(SystemExit) as e:
        logger.info("Catching {:s}".format(str(e)))
        pymchelper.utils.mcscripter.main([])
        assert e.value == 2

the assertion is never reached, so the test will always pass. I saw this pattern a few places at various tests.

grzanka commented 7 months ago

Interesting, what would happen if you change it to e.value == 2 ? The idea of that test is to check for non-zero exit code if no arguments are provided.

nbassler commented 7 months ago

You can put any value there, the assert line is not evaluated. :) Remove one indention, and it will behave as it should.

E.g. https://github.com/nbassler/dicomfix/blob/da577bf0bb05fbe269b23eec50d69a5a22970d9a/tests/test_simple.py#L19

grzanka commented 7 months ago

You are right ! pytest documentation says so as well: https://docs.pytest.org/en/4.6.x/reference.html#pytest-raises

image