-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Pytest-qatouch is a pytest plugin that automatically reports your pytest execution to your qatouch project.
Hey! 👋 You can check out this video to get started or read the following sections
Let's create a simple pytest project
- Create a new folder/directory and open your favorite editor "here I am using VSCode"
mkdir pytest-qatouch-example
code ./pytest-qatouch-example
- [Optional step] Create a new python virtual environment, activate it and update pip with other tools or use your current environment and skip this step
python -m venv env
env/Scripts/activate.bat # For windows or env/Scripts/activate.sh for Linux
python -m pip install -U pip wheel setuptool
- Install pytest and pytest-qatouch
pip install pytest pytest-qatouch
- Create a pytest configuration file with your configurations "Here I will use a
pytest.ini
file, so create one and add the following configurations"
[pytest]
addopts =
--verbose
testpaths =
tests
It just tells
pytest
to be verbose "log more info" and to look for the tests under the./tests
folder
- Create a test file "test_pytest_qatuch_plugin.py" under the
./tests
folder and add the following code
import pytest
def test_for_testcase_0001():
# Whatever the things you do here, in the end, it will be a passed test
assert 1+1+1 == 3
def test_for_testcase_0002():
# Whatever the things you do here, in the end, it will be a failed test
assert 1+1+1 == 1
@pytest.mark.parametrize(
"num1,num2",
[
pytest.param(8, 10),
pytest.param(0, 10)),
pytest.param(1, 4),
],
)
def test_sum_greater_than10(num1, num2):
assert num1+num2 >= 10
- Runpytest to make sure everything work fine
pytest
Create a testrun in your qatouch project, and save the needed configurations
- Log to your qatouch portal and open one of your projects or create a dummy one
- Create or open a test run with all or some of your test cases
- In the test run header press the "Config" button
- Save the configuration values that appear in the
webdriver.io
orcypress
tab as they will be used in the following steps
ℹ️ Note At this point you know the values for
qatouch-subdomain:
which is thedomain
you retrieved forwebdriver.io
orcypress
tabqatouch-api-token:
which is theapiToken
you retrieved forwebdriver.io
orcypress
tabqatouch-project-key:
which is theprojectKey
you retrieved forwebdriver.io
orcypress
tabqatouch-testrun-key:
which is thetestRunId
you retrieved forwebdriver.io
orcypress
tab
- Open the previously created test file "test_pytest_qatuch_plugin.py" and mark each test by the corresponding test case in your qatouch portal like int he code below
import pytest
from pytest_qatouch import qatouch # need to import this to mark each test and let pytest know each test corresponds to what in qatouch
@qatouch.TR(1) # Which corresponds to the test case TC0001/TR0001
def test_for_testcase_0001():
# Whatever the things you do here in the end it will be a passed test
assert 1+1+1 == 3
@qatouch.TR(2) # Which corresponds to the test case TC0002/TR0002
def test_for_testcase_0002():
# Whatever the things you do here in the end it will be a failed test
assert 1+1+1 == 1
@pytest.mark.parametrize(
"num1,num2",
[
pytest.param(8, 10,marks=qatouch.TR(3)), # Which corresponds to the test case TC0003/TR0003
pytest.param(0, 10,marks=qatouch.TR(4)), # Which corresponds to the test case TC0004/TR0004
pytest.param(1, 4,marks=qatouch.TR(5)), # Which corresponds to the test case TC0005/TR0005
],
)
def test_sum_greater_than10(num1, num2):
assert num1+num2 >= 10
ℹ️ Note In my case I will link the following test cases from my qatouch portal
Create a pytest configuration file with your configurations "Here I will use a pytest.ini
file, so create one and add the following configurations"
- Update the pytest configuration file with your qatouch configurations in your
pytest.ini
and add the following
[pytest]
addopts =
--verbose
--qatouch= <True/False>
--qatouch-subdomain= <YourDomain>
--qatouch-api-token= <YourToken>
--qatouch-project-key= <YourProjectKey>
--qatouch-testrun-key= <YourTestRunKey>
testpaths =
tests
Or you can do the following
[pytest]
addopts =
--verbose
--qatouch= <True/False>
--qatouch-subdomain= <YourDomain>
--qatouch-api-token= <YourToken>
--qatouch-project-key= <YourProjectKey>
--qatouch-testrun-key= <YourTestRunKey>
testpaths =
tests
ℹ️ Note You can override any value in the configuration file while running
pytest
from the cli like for example If enabledqatouch
and want to disable it or change the defaulttestrun-key
you add in the configuration file you can do like the following
pytest --qatouch=False
pytest --qatouch-testrun-key=<AnotherTestRunKey>
Run pytest 🎉
Just run pytest
in your terminal, and after it finishes it should report your execution to your qatouch portal
- If you want to have multiple configurations (different combinations of configurations for different purposes ), you need to create differently file for each one and pass that file to
pytest
while running from the cli, like the following
pytest -c .\qatouch-config.ini # or any-custom-file.ini