Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add feature to pad iteration number #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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
--------------------

22 changes: 20 additions & 2 deletions pytest_repeat.py
Original file line number Diff line number Diff line change
@@ -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(