Your question
I would like to be able to write tests that use goto and click, and have the test automatically fail if the navigation results in an unsuccessful status.
I tried this:
@pytest.fixture(autouse=True)
def fail_on_failure(page):
def _finished(response):
assert response.status == 200, f"{response.request.method} {response.url} returned {response.status}"
page.on("response", _finished)
My test had a page.click that produced a 500 error. I see the assert exception in a traceback in my test results, but only because a subsequent assert failed.
I also tried:
@pytest.fixture(autouse=True)
def fail_on_failure(page):
def _finished(response):
if response.status == 500:
pytest.fail(f"{response.request.method} {response.url} returned {response.status}")
page.on("response", _finished)
This caused pytest to freeze after my test with a Fail. The failure seems to be due to the pytest.fail (I removed the subsequent assert and the test still failed), but pytest becomes stuck.
Is there a way to systemically fail tests if any request fails?
Your question
I would like to be able to write tests that use
gotoandclick, and have the test automatically fail if the navigation results in an unsuccessful status.I tried this:
My test had a
page.clickthat produced a 500 error. I see the assert exception in a traceback in my test results, but only because a subsequent assert failed.I also tried:
This caused pytest to freeze after my test with a Fail. The failure seems to be due to the
pytest.fail(I removed the subsequent assert and the test still failed), but pytest becomes stuck.Is there a way to systemically fail tests if any request fails?