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_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 HTTP requests

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 HTTP 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_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,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/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.3.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

pytest_recorder-0.3.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_recorder-0.3.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.5.0

File hashes

Hashes for pytest_recorder-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b2acb2333f66392c6d9ba3309962119a23250e640383ffc308e81938f68dca17
MD5 61ceacc32b4f49769b1fa612e898d182
BLAKE2b-256 e93f9fd41e0f512b66dbbea1f24eea5f0e857c7753caa7fe7c409cf904ad6fd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_recorder-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.5.0

File hashes

Hashes for pytest_recorder-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cdc07925a0b1a73448a4a8a58c53682ee3f3dd17d08cfe2a30bacd8395d9dcad
MD5 7a9a8b9e906289e952741711eef26187
BLAKE2b-256 d92b2bda18881ecabf2db445d83f2e23a79208195259f7d4ec8de7fa5a4d6e42

See more details on using hashes here.

Supported by

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