I have bunch of test methods that i need to run and then after each test i want to update my results somewhere else. This is what i have:
@pytest.mark.testcasename('1234')
@pytest.mark.parametrize('lang',
["EN", "FR"])
def test_text(self, request, base_url, lang):
testrail_conn = TestrailHelper()
test_case_id = request.node.get_marker("testcasename").args[0]
base_url = base_url.replace("testEN", "testFR") if lang == "FR" else base_url
self.navigate(base_url)
self.wait_for_page_loaded()
results = self.check_text(lang)
try:
assert results
testrail_conn.update_test_status(test_case_id, test_result=1)
except AssertionError:
testrail_conn.update_test_status(test_case_id, test_result=5)
My problem is that i want the update_test_status to be in a teardown fixture where i can pass my test_result to it. This way i dont need to write same code for each test method.. Any ideas?
Thanks
You could store something on the
request
object, e.g. onrequest.node
- see the docs. Alternatively, you could use your fixture (as an argument) from the test, and store something there - or make the fixture return/yield some kind of data structure to store things in.