DEV Community

Konstantin
Konstantin

Posted on

PyTest assertions

You have probably seen how PyTest reports errors:

def test_make_empty_file():
    name = "/tmp/empty_test"
    make_empty_file(name)
    with open(name, "r") as fp:
    > assert not fp.read()
    E assert not 'hello'
    E + where 'hello' = ()
    E      +  where = .read

But do you know how it does it? And have you ever seen the error like

assertion failed, but when it was re-run for printing intermediate values, it did not fail.

I do really recommend reading this article http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html

Top comments (1)

Collapse
 
codemouse92 profile image
Jason C. McDonald

Hi Konstatin,

We encourage the entire article to be published on DEV.to (if you have proper rights), with a linkback if appropriate. Otherwise, we recommend original material, such as an original commentary on the article.

Posts that are simply intended to encourage readers to view an external resource are discouraged.

Thank you.