我一直在使用Python的unittest2
,最近刚开始迁移到pytest
。自然而然地,我试着做一些类比,但有一件事我就无法解决:
问题:为什么Pytest无法识别我在“test”类中定义的测试方法。
对我有效的方法
# 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'
在
pytest.ini
中,我有以下配置:# pytest.ini
[pytest]
python_files = *_test.py
python_classes = *TestSuite
# Also tried
# python_classes = *
# That does not work either
不确定其他什么信息可以用于调试?
感激任何建议。
TestSuiteLogin
,它是否有效?您确定.ini
正在被使用吗? - jonrsharpeobject
以获得新样式类,这就是为什么我说这不是问题的原因。这似乎非常奇怪! - jonrsharpepy.test
时,它会被检测到。这个数据点有帮助吗? - Ameypython_classes=
的设置,它就不能正常工作。即使是全匹配的python_classes=*
也不行。一旦我删除或注释该行设置,它就能正常工作。 - Amey