一直使用Pythonunittest2
,并且刚刚开始迁移到pytest
。当然,我试图进行比较,但我无法弄清楚的一件事是:
Question为什么 Pytest 不选择“测试”类中定义的测试方法。
什么对我有用
# 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'
什么对我不起作用(不起作用=测试方法没有被发现)
# 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
不确定调试此问题还需要哪些其他信息?
任何建议表示赞赏。
我刚刚遇到了类似的问题。我发现如果你以“Test”开头的类命名,那么 pytest 会选择它们,否则你的测试类将不会被发现。
这有效:
class TestClass:
def test_one(self):
assert 0
这不会:
class ClassTest:
def test_one(self):
assert 0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)