diff --git a/README.rst b/README.rst index 2ebe9800..9bab580b 100644 --- a/README.rst +++ b/README.rst @@ -88,6 +88,39 @@ For example: This will attempt to run test_file.py 1000 times, but will stop as soon as a failure occurs. +Padding test iteration count +---------------------------- + +Use the :code:`--repeat-pad` command line option to specify the character to be used +to pad the test iteration number, i.e. by prepending a :code:`0` or a space. +This feature helps sorting the results in a generated report, i.e. the one made by +pytest-html. + +.. code-block:: bash + + $ pytest --count=10 --repeat-pad=" " test_file.py + + ============================ test session starts ============================ + [...] + test_file.py .......... [100%] + + ================================== PASSES =================================== + ========================== short test summary info ========================== + PASSED test_file.py::test_do_nothing[ 1-10] + PASSED test_file.py::test_do_nothing[ 2-10] + PASSED test_file.py::test_do_nothing[ 3-10] + PASSED test_file.py::test_do_nothing[ 4-10] + PASSED test_file.py::test_do_nothing[ 5-10] + PASSED test_file.py::test_do_nothing[ 6-10] + PASSED test_file.py::test_do_nothing[ 7-10] + PASSED test_file.py::test_do_nothing[ 8-10] + PASSED test_file.py::test_do_nothing[ 9-10] + PASSED test_file.py::test_do_nothing[10-10] + ============================ 10 passed in 0.02s ============================= + +If more than one character is given, the setting is ignored. + + UnitTest Style Tests -------------------- diff --git a/pytest_repeat.py b/pytest_repeat.py index 008b692b..3980282c 100644 --- a/pytest_repeat.py +++ b/pytest_repeat.py @@ -23,6 +23,14 @@ def pytest_addoption(parser): choices=('function', 'class', 'module', 'session'), help='Scope for repeating tests') + parser.addoption( + '--repeat-pad', + action='store', + type=str, + default=None, + help='Character to be used for padding and aligning test repetions' + ) + def pytest_configure(config): config.addinivalue_line( @@ -60,8 +68,18 @@ def pytest_generate_tests(metafunc): if count > 1: metafunc.fixturenames.append("__pytest_repeat_step_number") - def make_progress_id(i, n=count): - return '{0}-{1}'.format(i + 1, n) + pad_char = metafunc.config.option.repeat_pad + if pad_char is not None and len(pad_char) != 1: + warnings.warn("Padding should be by a character only") + if pad_char is not None and len(pad_char) == 1: + n_digits = len(str(count)) + + def make_progress_id(i, n=count): + return f"{i + 1:{pad_char}>{n_digits}}-{n}" + else: + + def make_progress_id(i, n=count): + return '{0}-{1}'.format(i + 1, n) scope = metafunc.config.option.repeat_scope metafunc.parametrize(