Always worked with python unittest2
, and just started migrating to pytest
. Naturally I am trying to draw parallels and one thing I am just not able to figure out is:
Question Why does Pytest not pick up my test methods defined inside a "test" class.
What works for me
# login_test.py
import pytest
from frontend.app.login.login import LoginPage
@pytest.fixture
def setup():
login = LoginPage()
return login
def test_successful_login(setup):
login = setup
login.login("incorrect username","incorrect password")
assert login.error_msg_label().text == 'Invalid Credentials'
What does not work for me (Does not work = Test methods do not get discovered)
# login_test.py
import pytest
from frontend.app.login.login import LoginPage
class LoginTestSuite(object):
@pytest.fixture
def setup():
login = LoginPage()
return login
def test_invalid_login(self, setup):
login = setup
login.login("incorrect username","incorrect password")
assert login.error_msg_label().text == 'Invalid Credentials'
In pytest.ini
I have
# pytest.ini
[pytest]
python_files = *_test.py
python_classes = *TestSuite
# Also tried
# python_classes = *
# That does not work either
Not sure what other information is necessary to debug this?
Any advice is appreciated.
I was just running into a similar problem. I found that if you name your classes starting with "Test" then pytest will pick them up, otherwise your test class will not get discovered.
This works:
class TestClass:
def test_one(self):
assert 0
This does not:
class ClassTest:
def test_one(self):
assert 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With