Skip to main content

Requirements

  • Python 2.6 or 3.x and later

Features

  • Provide pytest.mark.randomize function for generating random test data

Installation

$ easy_install pytest-quickcheck # or
$ pip install pytest-quickcheck

Quick Start

Just pass the signature of function to randomize marker. The signature is represented a tuple consist of argument name and its type.

@pytest.mark.randomize(("i1", "int"), ("i2", "int"), ncalls=1)
def test_generate_ints(i1, i2):
    pass

More complex data structure:

@pytest.mark.randomize(
    ("d1", "{'x': int, 'y': [str, (int, int)], 'z': {'x': str}}")
)
def test_generate_dict(d1):
    pass

The randomize marker is able to use with parametrize marker.

@pytest.mark.parametrize("prime", [2, 3, 5])
@pytest.mark.randomize(("i1", "int"), ("f1", "float"), ncalls=1)
def test_gen_parametrize_with_randomize_int_float(prime, i1, f1):
    pass

Using command line option --randomize restricts only the randomize test.

$ py.test -v --randomize test_option.py
==========================================================================================
test session starts
==========================================================================================
test_option.py:5: test_normal SKIPPED
test_option.py:8: test_generate_ints[74-22] PASSED

Usage

There some options for each data type:

$ py.test --markers
@pytest.mark.randomize((argname, type), **options): mark the test function with
random data generating any data type.
  There are options for each data type: (see doc for details)
  int: ['min_num', 'max_num']
  float: ['min_num', 'max_num', 'positive']
  str: ['encoding', 'fixed_length', 'max_length', 'str_attrs']
  • common option

    ncalls: set the number of calls. Defaults to 3. (e.g. ncalls=5)
    choices: choose from given sequence. (e.g. choices=[3, 5, 7])
  • int

    min_num: lower limit for generating integer number. (e.g. min_num=0)
    max_num: upper limit for generating integer number. (e.g. max_num=10)
  • float

    min_num: lower limit for generating real number. (e.g. min_num=0.0)
    max_num: upper limit for generating real number. (e.g. max_num=1.0)
    positive: generate only positive real number if set to True. Defaults to False. (e.g. positive=True)
  • str

    encoding: generate unicode string encoded given character code. (e.g. encoding=”utf-8”) # for Python 2.x only
    fixed_length: generate fixed length string. (e.g. fixed_length=8)
    max_length: generate the string less than or equal to max length (e.g. max_length=32)
    str_attrs: generate the string in given letters. set a tuple consist of attribute names in the string module. (e.g. str_attrs=(“digits”, “punctuation”)

Probably, pytest_quickcheck/tests/test_plugin_basic.py is useful for learning how to use these options.

ChangeLog

0.5 (2012-03-18)

  • first release

Metadata

Release files for pytest-quickcheck 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-quickcheck 0.5
File Size Uploaded Provenance Actions
pytest-quickcheck-0.5.tar.gz 9.9 kB Without provenance Details for pytest-quickcheck-0.5.tar.gz

Release files / pytest-quickcheck-0.5.tar.gz

Download URL pytest-quickcheck-0.5.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8ef3c07aa91f6af8c89c5f7c5b286edc70827822dc51be0fd32d3c3c7065b0a4
BLAKE2b-256 checksum
How to use checksums
b880aac74f33ab79fa9ce31b4c07d7f1b53e745cfa96bf26f18d8abcb4221872
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pytest-quickcheck 0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page