Question on pytest example code
Terry Reedy
tjreedy at udel.edu
Sun Jan 10 23:00:47 EST 2016
On 1/10/2016 2:38 PM, Robert wrote:
> Hi,
>
> Below is a code snippet from pytest package. It passes pytest, i.e. there is
> no failure report.
>
>
> # content of test_sysexit.py
> import pytest
>
> def f():
> raise SystemExit(1)
>
> def test_mytest():
> with pytest.raises(SystemExit):
> f()
>
>
> I see that f() will generate 'SystemExit(1)'. Then what does function
> test_mytest()?
What does test_mytest do? It tests that f() raises SystemExit.
> Is it missing some assert line?
The unittest version of 'pytest.raises' is 'self.assertRaises'. The
latter context manager __exit__ method checks that it is passed the
exception given to the __enter__ method and fails if not. I presume the
pytest version is more or less identical.
> The above code is from page 5 (9 of 93) of 'pytest Documentation'
> Release 2.8.2
--
Terry Jan Reedy
More information about the Python-list
mailing list