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.4.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

pytest_recorder-0.4.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_recorder-0.4.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.19 Darwin/24.2.0

File hashes

Hashes for pytest_recorder-0.4.2.tar.gz
Algorithm Hash digest
SHA256 f32862caa684d92ed19173e1c2c3fe9af60aa2e50f752e753c28020a7e7e0fb3
MD5 1087361d824fba5b601a418c50eced41
BLAKE2b-256 1bb9de129286037714c1bed88110e0d3817b99c0c8e1ec3067895b3e0a50d769

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_recorder-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.19 Darwin/24.2.0

File hashes

Hashes for pytest_recorder-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d98215233bd793a216304f0956e9d7c318ea34a5399c3e0b3007973622ff608d
MD5 7a3463af68676dc0ba3bd3d0450fa6bd
BLAKE2b-256 f42b2ad0a3b86828c926d18725e125ba7700a8bdbd8fec06c8157a9e29f342ad

See more details on using hashes here.

Supported by

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