In this project I demonstrate how to use Python with Pytest and Requests for automation api tests.
This project includes:
-
Framworks:
- Pystest
- Requests
-
Features:
- Tests with JWT Api Authentication
- Pytest fixtures and parametrize
- Data drive tests
- Help functions
- Dafault http client for all tests
- Json Schema validation
- Page Object Pattern
- Report with Allure
- Code lint with Pylint
- Simple docker commands with Make
For this tests i use a local api which can be found here: Simple jwt local api
- Python >= 3.6 - How install Pytohn
- Pip >= 20.0.x - How install pip
- Docker >= 18.09 - How install Docker
- Allure Cliente >= 2.9 How install allure client
Install dependencies:
$ pip install --no-cache-dir -r requirements.txt
Export your api adress to BASE_URL variable, for this project:
$ export BASE_URL=http://localhost:3000/
$ pytest -vv -p no:cacheprovider --alluredir=./reports/allure_results
Pytest.ini is configured so that pytest executes any file, class or function that contains the text test as a sulfix, to change this, delete or edit the content of pytest.ini
You must have the allure client installed
Run the command below to generate the test report:
$ allure generate --clean ./reports/allure_results/ -o ./reports/allure-report
To view the report in the browser:
$ allure open ./reports/allure-report/
To lint the code:
$ pylint *
To start the tests with docker:
$ export BASE_URL=http://localhost:3000/
build imagem:
$ make -i build
Run the tests:
$ make test
To copy the report files to local reports folder:
$ make report.get
To generate reports:
You must have the allure client installed
Run the command below to generate the test report:
$ allure generate --clean ./reports/allure_results/ -o ./reports/allure-report
To view the report in the browser, run the command:
$ allure open ./reports/allure-report/