How to show number of successful tests? #10485
-
I am new to pytest so I might be missing something. I know it's possible since its shown in the docs website. But for some reason, it doesn't show for me. My file structure and file content is as follows,
# test_1.py
assert 1==1 # test_2.py
assert 1==2 # __init__.py And when I run
What I was expecting was at least an acknowledgement that there was one successful test. Something like,
Preferably I'd want it to show,
It's also showing that it collected 0 items? I have tried examples in getting-started and output pages, but nothing seems to work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Like those examples you link, your tests should be in a |
Beta Was this translation helpful? Give feedback.
-
Tests aren't supposed to be module-level assertions; they're supposed to be functions containing assertions (or classes with methods containing assertions, but let's not get into that right now). You need to rewrite def test_good():
assert 1 == 1 and def test_bad():
assert 1 == 2 Now pytest will be able to collect your tests and report on how many passed & how many failed. |
Beta Was this translation helpful? Give feedback.
Like those examples you link, your tests should be in a
def test_...():
function, not at the module body.