Skip to main content

PyQuickTest

PyQuickTest is an experimental python testing framework designed to deliver an easy-and-quick-to-start python testing mechanism.

Getting started

PyQuickTest test kit is divided into few categories:

Decorators

@is_test

Transform the decorated function into a test function for the framework.
example:
    "my_function" is not a test.
    def my_function():
        ok()
    ~~~~~~~~~~~~
    "my_function" is a test.
    @is_test()
    def my_function():
        ok()

@qpt_group

Categorize the decorated function as belonging to the given groups and subgroups. Groups and subgroups should be given as arguments.
example:
    "my_function" has no test group.
    @is_test()
    def my_function():
        ok()
~~~~~~~~~~~~~~
    "my_function" belong to the test group "Group".
    @is_test()
    @qpt_group("Group")
    def my_function():
        ok()
~~~~~~~~~~~~~~
    "my_function" belong to the test group "Group" and subgroup "Subgroup".
    @is_test()
    @qpt_group("Group", "Subgroup")
    def my_function():
        ok()

@qpt_execnbr

Order the decorated test function to be run a given number of times.
example:
    "my_function" is run once.
    @is_test()
    def my_function():
        ok()
    ~~~~~~~~~~~~
    "my_function" is run 100 times.
    @is_test()
    @qpt_execnbr(100)
    def my_function():
        ok()

@qpt_parametrize

Use the given parameters to the test function.
example:
    "my_function" will fail once tested because no arg is provided.
    @is_test()
    def my_function(arg):
        ok()
    ~~~~~~~~~~~~~~
    "my_function" will will be run with arg = 8.
    @is_test()
    @qpt_parametrize(8)
    def my_function(arg):
        ok()
    ~~~~~~~~~~~~~~
    "my_function" will will be run with arg1 = 8, arg2 = 'a' and arg3 = [45.19].
    @is_test()
    @qpt_parametrize(8, 'a', [45.19])
    def my_function(arg1, arg2, arg3):
        ok()

Assertion functions

ok

Validate the current test.
example:
    The test "my_function" will pass.
    @is_test()
    def my_function(arg):
        ok()

ko

Unvalidate the current test with an optional error message.
example:
    The test "my_function" will fail.
    @is_test()
    def my_function(arg):
        ko("This test failed!")

check

Unvalidate the current test if the given boolean is False. An optional error message can be provided. If the given boolean is True, do nothing.
example:
    The test "my_function" will fail if the generated number 'a' is lower than 10.
    @is_test()
    def my_function(arg):
        a = gen_int()
        check(a > 10, "a isn't greater than 10")
        ok()

ensure

Validate or unvalidate the current test depending on the given boolean. An optional error message can be provided.
example:
    The test "my_function" will pass if the generated number 'a' if greater than 10, and fail otherwise.
    @is_test()
    def my_function(arg):
        a = gen_int()
        ensure(a > 10, "a isn't greater than 10")

Generator functions

gen_none

Generate None.

gen_bool

Generate a random boolean.

gen_int

Generate a random integer. Min and max can be provided.

gen_signed_int

Generate a random signed integer. Min / max can be given.

gen_float

Generate a random float.

gen_signed_float

Generate a random signed float. Min and max can be given.

gen_ascii_lower_char

Generate a random ascii lower char.

gen_ascii_upper_char

Generate a random ascii upper char.

gen_ascii_char

Generate a random ascii char.

gen_ascii_lower_string

Generate a random ascii lower string.

gen_ascii_upper_string

Generate a random ascii upper string.

gen_ascii_string

Generate a random ascii string.

gen_callable

Generate a random callable. The number of arguments can be specified with nbr_args, as well as the generator function for the returned value with gen_return. If raised_exception = True, then the callable will raise an exception.

gen_generator

Generate a random iterator. The iterator length can be provided, as well as the elements generator function with the gen_element argument.

gen_list

Generate a random list. The list length can be provided, as well as the elements generator function with the the gen_element argument.

gen_dict

Generate a random dict. The dict length can be provided, as well as the keys generator function with the the gen_keys argument, and the element generator function with the gen_element argument.

gen_random_value

Generate a random value from any single value generator decorated with the "is_gen_value" flag attribute.

gen_random_iterable

Generate a random iterable from any iterable generator decorated with the "is_gen_iterable" flag attribute.

gen_random

Generate a random data from any generator decorated with the "is_gen" flag attribute.

Testing functions

test_one

Run a single test function. A few optional arguments can be provided, but if this function is directly used alone, only passing the test function as a parameter is certainly enough.
example:
    Run the test "my_function".
    test_one(my_function)
    ~~~~~~~~~~~~~~~
    Run the test "my_function" with a printed prefix "==>" before the test result output.
    test_one(
        my_function,
        prefix="==>"
    )
    ~~~~~~~~~~~
    Run the test "my_function" with an indentation of 4 spaces and a printed prefix "==>" before the test result output.
    test_one(
        my_function,
        prefix="==>"
        indent=4
    )

test_group

Run a group of test functions. If you want to run a subgroup, pass every group and subgroup as a parameter. If no context is provided, it will be obtained by importing the caller file. If a filename is provided, the context will be retrieved from this file.
example:
    Run the test functions from group "G".
    test_group("G")
    ~~~~~~~~~~
    Run the test functions from group "G" and subgroup "Subgroup".
    test_group(
        "G",
        "Subgroup"
    )
    ~~~~~~~~~
    Run the test functions from group "G", subgroup "SG" and sub-subgroup "SSG".
    test_group(
        "G",
        "SG",
        "SSG",
        filename="tests.py"
    )

test_all

Run every test functions. If no context is provided, it will be obtained by importing the caller file. If a filename is provided, the context will be retrieved from this file.
example:
    Run the test functions from caller file context.
    test_all()
    ~~~~~~
    Run the test functions from file "test.py".
    test_all(
        filename="tests.py"
    )

Installation

TBA

Metadata

Release files for PyQuickTest 0.1.0

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

Source distribution (sdist)

Source distribution for PyQuickTest 0.1.0
File Size Uploaded
PyQuickTest-0.1.0.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyQuickTest 0.1.0
File Interpreter ABI Platform
PyQuickTest-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.1 kB

Release files / PyQuickTest-0.1.0.tar.gz

Download URL PyQuickTest-0.1.0.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1c9b8292e2b5075aa89519b8741c81a161d755ab4acef1ced28ed8ad69e4f75c
BLAKE2b-256 checksum
How to use checksums
d26bab089a40133f5fa7afc32ada1f587b145817b20d10a364c7ac544179ed8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / PyQuickTest-0.1.0-py3-none-any.whl

Download URL PyQuickTest-0.1.0-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a537966d5116401637f00bbd9fd53a20a0508b0a4413c62367798e3af5f99e69
BLAKE2b-256 checksum
How to use checksums
41023d98e678fe40ff00b8d2b16311b5217b5553fed6db5f551163595380faf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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