Skip to main content

Pytest plugin, meant to facilitate unit tests writing for tools consumming Web APIs.

Project description

1. TL;DR example

STEP 1

Write this code:

File tests/some_module.py

@pytest.mark.record_curl
@pytest.mark.record_ftp
@pytest.mark.record_http
@pytest.mark.record_time
@pytest.mark.record_verify_screen
def test_some_test(record):
    some_python_object = ...

    record.add_verify(object=some_python_object)

STEP 2

Run:

pytest tests/some_module.py --record

It will:

Save all the Curl and urllib3 requests, as well as interactions with ftplib.

Save the execution datetime

Save the screen output

Save the data you provide to recorder object

STEP 3

Run:

pytest tests/some_module.py

It will:

Reuse the stored Curl and urllib3 requests

Reuse the same datetime to execute the test

Compare the current screen output to the previous one and raise and exception if different

Compare the current recorder object data to the previous one and raise and exception if different

2. Detailed example

CODE

@pytest.mark.record_curl
@pytest.mark.record_http
@pytest.mark.record_time(date=datetime(2023, 3, 1, 12, 0, 0), tic=False)
@pytest.mark.record_verify_screen(hash=True)
def test_some_test(record):
    ...
    record.hash_only = True
    record.add_verify(object=df)
    record.add_verify(object=[df])

    recorder.add_verify(
        object=df,
    )

USAGE

pytest [FILE] [--record[=none,all,curl,ftp,http,object,screen,time]] [--record-no-overwrite] [--record-no-hash]

FILES

For a given test_function from test_module, we will have the following files:

/tests/test_module.py:test_function

/tests/record/curl/test_module/test_function.yaml

/tests/record/ftp/test_module/test_function.yaml

/tests/record/http/test_module/test_function.yaml

/tests/record/object/test_module/test_function.json

/tests/record/object_hash/test_module/test_function.txt/json?

/tests/record/screen/test_module/test_function.txt/json?

/tests/record/screen_hash/test_module/test_function.txt/json?

/tests/record/time/test_module/test_function.txt/json?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_recorder-0.6.5.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_recorder-0.6.5-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_recorder-0.6.5.tar.gz.

File metadata

  • Download URL: pytest_recorder-0.6.5.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.11 Darwin/25.3.0

File hashes

Hashes for pytest_recorder-0.6.5.tar.gz
Algorithm Hash digest
SHA256 b24c9c4d3f4f1245f3e0467218dee4ad0a807b086a6beff508be77fbb8071517
MD5 abb00f49f03653a786001bb5afda7997
BLAKE2b-256 037e5400e95bf66a29703e8a89da065e1b66b9f8ce1707635f49ef0bb8849771

See more details on using hashes here.

File details

Details for the file pytest_recorder-0.6.5-py3-none-any.whl.

File metadata

  • Download URL: pytest_recorder-0.6.5-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.11 Darwin/25.3.0

File hashes

Hashes for pytest_recorder-0.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c35a36439ca1e9d781344d56faffbe07eee70f976afa3ebd1acd0b59277070ea
MD5 32501c416f8e836b627ff2add34c35d6
BLAKE2b-256 0731e185d05db20d15ee69d479f39298322a0d5e395ec4c050bf8d74c027f234

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page