[英]pytest --help does not run when using pytest_configure() in conftest.py
[英]Expected results of Assertion Errors are not showing up when using Pytest and conftest.py file
我正在使用 Pytest 来测试我的网站内容。 我的 conftest.py 中有一个修复程序,它创建了一个 webdriver 供其他测试参考。 当测试运行期间发生错误时,仅显示AssertionError
,而不是在assert
语句中测试的实际值和预期值。
这是我的 conftest.py 文件:
import os
import pytest
from selenium import webdriver
@pytest.fixture(scope="session")
def setup(request):
driver_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'drivers')
driver = webdriver.Chrome()
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj, "driver", driver)
yield driver
driver.close()
这是我的高级测试文件:
import pytest
from validations import *
@pytest.mark.usefixtures("setup")
class TestOurServices:
def test_our_services_direct_navigation(self):
go_to_our_services(self.driver)
validate_our_services_content(self.driver)
然后这是一个输出示例:
这篇文章帮助解决了这个问题:
我在辅助函数中进行了断言,例如上面的validate_our_services_content
。 他们在一个名为validations.py
的文件中
参考上述问题,我创建了一个__init__.py
文件来声明这些验证:
__init__.py
import pytest
pytest.register_assert_rewrite('validations')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.