Framework Setup
Prerequisites
- Download and set up python3 from Download Python or you can use brew to install.
- This codebase supports 3.9+
It has been observed that sometimes the environment setup turns out to be a tedious and time taking task. But we have made it simple, now you just have to run a shell script and you are good to go.
Please follow the below commands to set up the test framework:
-
Clone the project (use ssh if possible).
-
Go to the project directory.
cd python-api-pytest
-
Run venv_setup.sh if you are mac or change the commands according to your os for setting up venv and downloading packages
sh venv_setup.sh
Framework Structure
-
utils - It contains all the client's libraries like aws, k8, and Jenkins. For reference please have a look here.
a. aws.py
b. k8.py
c. jenkins.py
-
docker - It contains the Dockerfile for creating the docker image of python in case if we need to run our test inside docker containers:
- /docker/
-
Jenkins-pipeline - It contains the Jenkinsfile which will be used to trigger our tests on Jenkins.
- Jenkinsfile
-
sample-jsons - It contains the environment data like baseUrl, database details.
-
tests - It contains the test class which needs to be triggered for execution.
-
allure-results - folder to save our allure report.
-
conftest - It is the heart of pytest, we will keep only fixture and pytest methods here. This file contains all the before and teardown fixtures and also database connections
- conftest.py
-
requirements.txt - we will write all our dependencies there and then download in one shot using venv_setup.sh
- requirements.txt
Execution
Running the pytest tests is very easy as it gets.
-
Complete the framework setup step
-
Activate the virtual environment
source venv/bin/activate
(run command inside python-api-pytest) -
If you want to run the tests with default parameters passed in the source code, Just run
pytest tests
and the execution will start. -
If you want to run the test with different params, you can pass the parameters as additional arguments in the command like
pytest tests --baseurl https://test.com
Reporting
We are using Allure Report as a reporting tool for this framework. Once your test execution is completed you can
run allure serve
and it will open the allure report on your default browser.
Allure report is a very fancy report and you can publish a lot of meaningful logs to it. It also shows the function description there.
Useful Doc’s
pytest: https://docs.pytest.org/en/6.2.x/index.html
Allure: https://docs.qameta.io/allure/#_python
PEP 8 -- Style Guide for Python Code: https://www.python.org/dev/peps/pep-0008/