This is a functional demo of how to integrate TestRail with pytest. I mainly use it for E2E web application testing using Selenium.
- Set variables in
testrail/consts.py
based on your TestRail setting - If necessary, test related variables are in
tests/consts.py
- All tests are linked with TestRail test cases by the decorator
@pytest.mark.testrail(id)
whereid
is the test case id in TestRail.
Except for the pytest's command line paramters, I also added some custom parameters:
--platform=<platform>
: this is used to specify test platform--browser=<browser>
: specify selenium webdriver--publish
: if set, result will be published on TestRail--include_all
: when creating a test run, include all test cases--tr_name=<test run name>
: when publishing, create a new test run with this name--tr_id=<run id>
: run tests given a test run--ids=id1,id2,id3....
: run tests with given id
I think use cases are more helpful in explaining how it works.
# as normal pytest case discovery, run tests in test_demo_class
# publish the result to TestRail using a auto-generated name
pytest test_demo_class --publish
# run all tests, publish results to a new test run, test run name is
# auto-generated
pytest --platform=qe --browser=0 --publish
# run all tests, publish results to a new test run named 'Auto Test Run'
pytest --publish --tr_name='Auto Test Run'
# run all tests in test run 123, publish results
pytest --tr_id=123
# only run test 1,2,3
pytest --ids=1,2,3
# create a new test run with all test cases, but only run test 1, 2, 3
# and publish results
pytest --ids=1,2,3 --publish --include_all
MIT