DEV Community

loading...

PyTest assertions

Konstantin
・1 min read

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

Discussion (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.

Forem Open with the Forem app