问题
I am trying to use the pytest testrail module and started with this demo script:
import pytest
from pytest_testrail.plugin import testrail
@testrail('C165')
def test_run():
print "T165:pass"
It does create a test run but does not post any results to the corresponding test cases.
回答1:
Try adding an assertion as that is what the pytest hook is looking for:
import pytest
from pytest_testrail.plugin import testrail
@testrail('C165')
def test_run():
assert False
回答2:
Here is add_result
function. The testrail
plugin executes it when your test (test_run) is finished.
You can notice the parameter status
in the function, it requires your test need to return the result from assertion (ex. assert False is good example).
In your case, just print a string is not good to testrail
know the status of the test.
def add_result(self, test_ids, status, comment='', duration=0):
"""
Add a new result to results dict to be submitted at the end.
:param list test_ids: list of test_ids.
:param int status: status code of test (pass or fail).
:param comment: None or a failure representation.
:param duration: Time it took to run just the test.
"""
来源:https://stackoverflow.com/questions/46287899/pytest-testrail-module-post-test-results-for-test-runs