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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_recorder-0.4.5.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.7 Darwin/24.3.0

File hashes

Hashes for pytest_recorder-0.4.5.tar.gz
Algorithm Hash digest
SHA256 9a2de07ff4391b2f27277e9ae54a6b2b19e38c5efe6b2082308fac64645f4a37
MD5 688e392a8240cbdbfcdfafcf5dfb5605
BLAKE2b-256 024a66a3055b498772a217e799a4a127fd6193485684971ab7eda6fc3382b74a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_recorder-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.7 Darwin/24.3.0

File hashes

Hashes for pytest_recorder-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ff544bbd17cb32f8bca15e1d996fa4bf5f2f414a19ce330267f15f29c626894d
MD5 f0e11858c0b89def986f9dca4091ea8d
BLAKE2b-256 9569769de72072eeb1fcb11f7bdc12c1b4be70820ef7d815a69ca96b4dd2c92f

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