Skip to content

Schveitzer/api-tests-python-pytest

Repository files navigation

Api tests Python Pytest

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

API

For this tests i use a local api which can be found here: Simple jwt local api

Requirements

Getting Started

Install dependencies:

$ pip install --no-cache-dir -r requirements.txt

Config

Export your api adress to BASE_URL variable, for this project:

$ export BASE_URL=http://localhost:3000/

To run tests:

$ 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

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:

$ allure open ./reports/allure-report/

Lint Code

To lint the code:

$ pylint *

Docker execution

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/

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published