File python-pytest-repeat.spec of Package python-pytest-repeat
#
# spec file for package python-pytest_repeat
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
Name: pytest-repeat
Version: 0.9.3
Release: 0
Summary: pytest plugin for repeating tests
License: This Source Code Form is subject to the terms of the Mozilla PublicLicense, v. 2.0. If a copy of the MPL was not distributed with thisfile, You can obtain one at https://www.mozilla.org/en-US/MPL/2.0/. (FIXME:No SPDX)
URL: None
Source: pytest_repeat-%{version}.tar.gz
BuildRequires: python-rpm-macros
BuildRequires: %{python_module hatchling}
BuildRequires: %{python_module pip}
# SECTION test requirements
BuildRequires: %{python_module pytest}
# /SECTION
BuildRequires: fdupes
Requires: python-pytest
BuildArch: noarch
%python_subpackages
%description
pytest_repeat
===================
pytest_repeat is a plugin for `pytest <https://docs.pytest.org>`_ that makes it
easy to repeat a single test, or multiple tests, a specific number of times.
|license| |python| |version| |anaconda| |ci| |issues|
.. |license| image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg
:target: https://github.com/pytest-dev/pytest_repeat/blob/master/LICENSE
.. |version| image:: http://img.shields.io/pypi/v/pytest_repeat.svg
:target: https://pypi.python.org/pypi/pytest_repeat
.. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest_repeat.svg
:target: https://anaconda.org/conda-forge/pytest_repeat
.. |ci| image:: https://github.com/pytest-dev/pytest_repeat/workflows/test/badge.svg
:target: https://github.com/pytest-dev/pytest_repeat/actions
.. |python| image:: https://img.shields.io/pypi/pyversions/pytest_repeat.svg
:target: https://pypi.python.org/pypi/pytest_repeat/
.. |issues| image:: https://img.shields.io/github/issues-raw/pytest-dev/pytest_repeat.svg
:target: https://github.com/pytest-dev/pytest_repeat/issues
Requirements
------------
You will need the following prerequisites in order to use pytest_repeat:
- Python 3.7+ or PyPy3
- pytest 4 or newer
Installation
------------
To install pytest_repeat:
.. code-block:: bash
$ pip install pytest_repeat
Repeating a test
----------------
Use the :code:`--count` command line option to specify how many times you want
your test, or tests, to be run:
.. code-block:: bash
$ pytest --count=10 test_file.py
Each test collected by pytest will be run :code:`count` times.
If you want to mark a test in your code to be repeated a number of times, you
can use the :code:`@pytest.mark.repeat(count)` decorator:
.. code-block:: python
import pytest
@pytest.mark.repeat(3)
def test_repeat_decorator():
pass
If you want to override default tests executions order, you can use :code:`--repeat-scope`
command line option with one of the next values: :code:`session`, :code:`module`, :code:`class` or :code:`function` (default).
It behaves like a scope of the pytest fixture.
:code:`function` (default) scope repeats each test :code:`count` or :code:`repeat` times before executing next test.
:code:`session` scope repeats whole tests session, i.e. all collected tests executed once, then all such tests executed again and etc.
:code:`class` and :code:`module` behaves similar :code:`session` , but repeating set of tests is a tests from class or module, not all collected tests.
Repeating a test until failure
------------------------------
If you are trying to diagnose an intermittent failure, it can be useful to run the same
test over and over again until it fails. You can use pytest's :code:`-x` option in
conjunction with pytest_repeat to force the test runner to stop at the first failure.
For example:
.. code-block:: bash
$ pytest --count=1000 -x test_file.py
This will attempt to run test_file.py 1000 times, but will stop as soon as a failure
occurs.
UnitTest Style Tests
--------------------
Unfortunately pytest_repeat is not able to work with unittest.TestCase test classes.
These tests will simply always run once, regardless of :code:`--count`, and show a warning.
Resources
---------
- `Release Notes <https://github.com/pytest-dev/pytest_repeat/blob/master/CHANGES.rst>`_
- `Issue Tracker <https://github.com/pytest-dev/pytest_repeat/issues>`_
- `Code <https://github.com/pytest-dev/pytest_repeat/>`_
%prep
%autosetup -p1 -n pytest_repeat-%{version}
%build
%pyproject_wheel
%install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%check
%files %{python_files}
%{python_sitelib}/*
%{python_sitelib}/*-%{version}.dist-info
%changelog