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