I am using Pytest to test my website content. I have a fixure in my conftest.py that creates a webdriver for other tests to reference. When an error occurs during a test run, only AssertionError
is displayed, as opposed to the actual and expected values being tested in the assert
statement.
Here is my conftest.py file:
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()
Here is my high-level test file:
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)
Then here is an example of the output:
This post helped solve the issue:
pytest assert introspection in helper function
I had assertions in helper functions such as validate_our_services_content
from above. They were in a file called validations.py
Referencing the above issue I created an __init__.py
file to declare those validations:
__init__.py
import pytest
pytest.register_assert_rewrite('validations')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.