From 6a9a1f881fa13cca109b865100b8de9fe1274077 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Tue, 11 Apr 2023 01:56:31 +0000 Subject: automatic import of python-pytest-reraise --- .gitignore | 1 + python-pytest-reraise.spec | 625 +++++++++++++++++++++++++++++++++++++++++++++ sources | 1 + 3 files changed, 627 insertions(+) create mode 100644 python-pytest-reraise.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore index e69de29..812f11c 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/pytest-reraise-2.1.2.tar.gz diff --git a/python-pytest-reraise.spec b/python-pytest-reraise.spec new file mode 100644 index 0000000..1e4e7c2 --- /dev/null +++ b/python-pytest-reraise.spec @@ -0,0 +1,625 @@ +%global _empty_manifest_terminate_build 0 +Name: python-pytest-reraise +Version: 2.1.2 +Release: 1 +Summary: Make multi-threaded pytest test cases fail when they should +License: MIT +URL: https://github.com/bjoluc/pytest-reraise +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/37/9b/efba721806e9018eee657dda66ffeaca7b5e6de26718b5e5aa7e62f60b03/pytest-reraise-2.1.2.tar.gz +BuildArch: noarch + +Requires: python3-pytest + +%description +# pytest-reraise + +[![PyPI](https://img.shields.io/pypi/v/pytest-reraise)](https://pypi.python.org/pypi/pytest-reraise/) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/bjoluc/pytest-reraise/build)](https://github.com/bjoluc/pytest-reraise/actions) +[![codecov](https://codecov.io/gh/bjoluc/pytest-reraise/branch/main/graph/badge.svg)](https://codecov.io/gh/bjoluc/pytest-reraise) +[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pytest-reraise)](https://pypi.python.org/pypi/pytest-reraise/) +![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-reraise) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/psf/black) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079)](https://github.com/bjoluc/semantic-release-config-poetry) + +Let's assume you write a pytest test case that includes assertions in another thread, like so: + +```python +from threading import Thread + +def test_assert(): + + def run(): + assert False + + Thread(target=run).start() +``` + +This test will pass, as the `AssertionError` is not raised in the main thread. +`pytest-reraise` is here to help you capture the exception and raise it in the main thread: + +```sh +pip install pytest-reraise +``` + +```python +from threading import Thread + +def test_assert(reraise): + + def run(): + with reraise: + assert False + + Thread(target=run).start() +``` + +The above test will fail, as `pytest-reraise` captures the exception and raises it at the end of the test case. + +## Advanced Usage and Special Cases + +### Wrapping Functions + +Instead of using the `reraise` context manager in a function, you can also wrap the entire function with it via the `reraise.wrap()` method. +Hence, the example +```python +def run(): + with reraise: + assert False + +Thread(target=run).start() +``` +can also be written as +```python +def run(): + assert False + +Thread(target=reraise.wrap(run)).start() +``` +or even +```python +@reraise.wrap +def run(): + assert False + +Thread(target=run).start() +``` + +### Manual Re-raising + +By default, the captured exception (if any) is raised at the end of the test case. +If you want to raise it before then, call `reraise()` in your test case. +If an exception has been raised within a `with reraise` block by then, `reraise()` will raise it right away: + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + reraise() # This will not raise anything yet + + t = Thread(target=run) + t.start() + t.join() + + reraise() # This will raise the assertion error +``` + +As seen in the example above, `reraise()` can be called multiple times during a test case. Whenever an exception has been raised in a `with reraise` block since the last call, it will be raised on the next call. + +### Multiple Exceptions + +When the `reraise` context manager is used multiple times in a single test case, only the first-raised exception will be re-raised in the end. +In the below example, both threads raise an exception but only one of these exceptions will be re-raised. + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + for _ in range(2): + Thread(target=run).start() +``` + +### Catching Exceptions + +By default, the `reraise` context manager does not catch exceptions, so they will not be hidden from the thread in which they are raised. +If you want to change this, use `reraise(catch=True)` instead of `reraise`: + +```python +def test_assert(reraise): + + def run(): + with reraise(catch=True): + assert False + print("I'm alive!") + + Thread(target=run).start() +``` + +Note that you cannot use `reraise()` (without the `catch` argument) as a context manager, as it is used to raise exceptions. + +### Exception Priority + +If `reraise` captures an exception and the main thread raises an exception as well, the exception captured by `reraise` will mask the main thread's exception unless that exception was already re-raised. +The objective behind this is that the outcome of the main thread often depends on the work performed in other threads. +Thus, failures in in other threads are likely to cause failures in the main thread, and other threads' exceptions (if any) are of greater importance for the developer than main thread exceptions. + +The example below will report `assert False`, not `assert "foo" == "bar"`. + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False # This will be reported + + t = Thread(target=run) + t.start() + t.join() + + assert "foo" == "bar" # This won't +``` + +### Accessing and Modifying Exceptions + +`reraise` provides an `exception` property to retrieve the exception that was captured, if any. +`reraise.exception` can also be used to assign an exception if no exception has been captured yet. +In addition to that, `reraise.reset()` returns the value of `reraise.exception` and resets it to `None` so that the exception will not be raised anymore. + +Here's a quick demonstration test case that passes: + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + t = Thread(target=run) + t.start() + t.join() + + # Return the captured exception: + assert type(reraise.exception) is AssertionError + + # This won't do anything, since an exception has already been captured: + reraise.exception = Exception() + + # Return the exception and set `reraise.exception` to None: + assert type(reraise.reset()) is AssertionError + + # `Reraise` will not fail the test case because + assert reraise.exception is None +``` + + +%package -n python3-pytest-reraise +Summary: Make multi-threaded pytest test cases fail when they should +Provides: python-pytest-reraise +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-pytest-reraise +# pytest-reraise + +[![PyPI](https://img.shields.io/pypi/v/pytest-reraise)](https://pypi.python.org/pypi/pytest-reraise/) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/bjoluc/pytest-reraise/build)](https://github.com/bjoluc/pytest-reraise/actions) +[![codecov](https://codecov.io/gh/bjoluc/pytest-reraise/branch/main/graph/badge.svg)](https://codecov.io/gh/bjoluc/pytest-reraise) +[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pytest-reraise)](https://pypi.python.org/pypi/pytest-reraise/) +![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-reraise) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/psf/black) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079)](https://github.com/bjoluc/semantic-release-config-poetry) + +Let's assume you write a pytest test case that includes assertions in another thread, like so: + +```python +from threading import Thread + +def test_assert(): + + def run(): + assert False + + Thread(target=run).start() +``` + +This test will pass, as the `AssertionError` is not raised in the main thread. +`pytest-reraise` is here to help you capture the exception and raise it in the main thread: + +```sh +pip install pytest-reraise +``` + +```python +from threading import Thread + +def test_assert(reraise): + + def run(): + with reraise: + assert False + + Thread(target=run).start() +``` + +The above test will fail, as `pytest-reraise` captures the exception and raises it at the end of the test case. + +## Advanced Usage and Special Cases + +### Wrapping Functions + +Instead of using the `reraise` context manager in a function, you can also wrap the entire function with it via the `reraise.wrap()` method. +Hence, the example +```python +def run(): + with reraise: + assert False + +Thread(target=run).start() +``` +can also be written as +```python +def run(): + assert False + +Thread(target=reraise.wrap(run)).start() +``` +or even +```python +@reraise.wrap +def run(): + assert False + +Thread(target=run).start() +``` + +### Manual Re-raising + +By default, the captured exception (if any) is raised at the end of the test case. +If you want to raise it before then, call `reraise()` in your test case. +If an exception has been raised within a `with reraise` block by then, `reraise()` will raise it right away: + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + reraise() # This will not raise anything yet + + t = Thread(target=run) + t.start() + t.join() + + reraise() # This will raise the assertion error +``` + +As seen in the example above, `reraise()` can be called multiple times during a test case. Whenever an exception has been raised in a `with reraise` block since the last call, it will be raised on the next call. + +### Multiple Exceptions + +When the `reraise` context manager is used multiple times in a single test case, only the first-raised exception will be re-raised in the end. +In the below example, both threads raise an exception but only one of these exceptions will be re-raised. + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + for _ in range(2): + Thread(target=run).start() +``` + +### Catching Exceptions + +By default, the `reraise` context manager does not catch exceptions, so they will not be hidden from the thread in which they are raised. +If you want to change this, use `reraise(catch=True)` instead of `reraise`: + +```python +def test_assert(reraise): + + def run(): + with reraise(catch=True): + assert False + print("I'm alive!") + + Thread(target=run).start() +``` + +Note that you cannot use `reraise()` (without the `catch` argument) as a context manager, as it is used to raise exceptions. + +### Exception Priority + +If `reraise` captures an exception and the main thread raises an exception as well, the exception captured by `reraise` will mask the main thread's exception unless that exception was already re-raised. +The objective behind this is that the outcome of the main thread often depends on the work performed in other threads. +Thus, failures in in other threads are likely to cause failures in the main thread, and other threads' exceptions (if any) are of greater importance for the developer than main thread exceptions. + +The example below will report `assert False`, not `assert "foo" == "bar"`. + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False # This will be reported + + t = Thread(target=run) + t.start() + t.join() + + assert "foo" == "bar" # This won't +``` + +### Accessing and Modifying Exceptions + +`reraise` provides an `exception` property to retrieve the exception that was captured, if any. +`reraise.exception` can also be used to assign an exception if no exception has been captured yet. +In addition to that, `reraise.reset()` returns the value of `reraise.exception` and resets it to `None` so that the exception will not be raised anymore. + +Here's a quick demonstration test case that passes: + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + t = Thread(target=run) + t.start() + t.join() + + # Return the captured exception: + assert type(reraise.exception) is AssertionError + + # This won't do anything, since an exception has already been captured: + reraise.exception = Exception() + + # Return the exception and set `reraise.exception` to None: + assert type(reraise.reset()) is AssertionError + + # `Reraise` will not fail the test case because + assert reraise.exception is None +``` + + +%package help +Summary: Development documents and examples for pytest-reraise +Provides: python3-pytest-reraise-doc +%description help +# pytest-reraise + +[![PyPI](https://img.shields.io/pypi/v/pytest-reraise)](https://pypi.python.org/pypi/pytest-reraise/) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/bjoluc/pytest-reraise/build)](https://github.com/bjoluc/pytest-reraise/actions) +[![codecov](https://codecov.io/gh/bjoluc/pytest-reraise/branch/main/graph/badge.svg)](https://codecov.io/gh/bjoluc/pytest-reraise) +[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pytest-reraise)](https://pypi.python.org/pypi/pytest-reraise/) +![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-reraise) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/psf/black) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079)](https://github.com/bjoluc/semantic-release-config-poetry) + +Let's assume you write a pytest test case that includes assertions in another thread, like so: + +```python +from threading import Thread + +def test_assert(): + + def run(): + assert False + + Thread(target=run).start() +``` + +This test will pass, as the `AssertionError` is not raised in the main thread. +`pytest-reraise` is here to help you capture the exception and raise it in the main thread: + +```sh +pip install pytest-reraise +``` + +```python +from threading import Thread + +def test_assert(reraise): + + def run(): + with reraise: + assert False + + Thread(target=run).start() +``` + +The above test will fail, as `pytest-reraise` captures the exception and raises it at the end of the test case. + +## Advanced Usage and Special Cases + +### Wrapping Functions + +Instead of using the `reraise` context manager in a function, you can also wrap the entire function with it via the `reraise.wrap()` method. +Hence, the example +```python +def run(): + with reraise: + assert False + +Thread(target=run).start() +``` +can also be written as +```python +def run(): + assert False + +Thread(target=reraise.wrap(run)).start() +``` +or even +```python +@reraise.wrap +def run(): + assert False + +Thread(target=run).start() +``` + +### Manual Re-raising + +By default, the captured exception (if any) is raised at the end of the test case. +If you want to raise it before then, call `reraise()` in your test case. +If an exception has been raised within a `with reraise` block by then, `reraise()` will raise it right away: + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + reraise() # This will not raise anything yet + + t = Thread(target=run) + t.start() + t.join() + + reraise() # This will raise the assertion error +``` + +As seen in the example above, `reraise()` can be called multiple times during a test case. Whenever an exception has been raised in a `with reraise` block since the last call, it will be raised on the next call. + +### Multiple Exceptions + +When the `reraise` context manager is used multiple times in a single test case, only the first-raised exception will be re-raised in the end. +In the below example, both threads raise an exception but only one of these exceptions will be re-raised. + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + for _ in range(2): + Thread(target=run).start() +``` + +### Catching Exceptions + +By default, the `reraise` context manager does not catch exceptions, so they will not be hidden from the thread in which they are raised. +If you want to change this, use `reraise(catch=True)` instead of `reraise`: + +```python +def test_assert(reraise): + + def run(): + with reraise(catch=True): + assert False + print("I'm alive!") + + Thread(target=run).start() +``` + +Note that you cannot use `reraise()` (without the `catch` argument) as a context manager, as it is used to raise exceptions. + +### Exception Priority + +If `reraise` captures an exception and the main thread raises an exception as well, the exception captured by `reraise` will mask the main thread's exception unless that exception was already re-raised. +The objective behind this is that the outcome of the main thread often depends on the work performed in other threads. +Thus, failures in in other threads are likely to cause failures in the main thread, and other threads' exceptions (if any) are of greater importance for the developer than main thread exceptions. + +The example below will report `assert False`, not `assert "foo" == "bar"`. + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False # This will be reported + + t = Thread(target=run) + t.start() + t.join() + + assert "foo" == "bar" # This won't +``` + +### Accessing and Modifying Exceptions + +`reraise` provides an `exception` property to retrieve the exception that was captured, if any. +`reraise.exception` can also be used to assign an exception if no exception has been captured yet. +In addition to that, `reraise.reset()` returns the value of `reraise.exception` and resets it to `None` so that the exception will not be raised anymore. + +Here's a quick demonstration test case that passes: + +```python +def test_assert(reraise): + + def run(): + with reraise: + assert False + + t = Thread(target=run) + t.start() + t.join() + + # Return the captured exception: + assert type(reraise.exception) is AssertionError + + # This won't do anything, since an exception has already been captured: + reraise.exception = Exception() + + # Return the exception and set `reraise.exception` to None: + assert type(reraise.reset()) is AssertionError + + # `Reraise` will not fail the test case because + assert reraise.exception is None +``` + + +%prep +%autosetup -n pytest-reraise-2.1.2 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-pytest-reraise -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Apr 11 2023 Python_Bot - 2.1.2-1 +- Package Spec generated diff --git a/sources b/sources new file mode 100644 index 0000000..5fee5d5 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +93547dad3c94ca0e544fa5e1e8e3b9f7 pytest-reraise-2.1.2.tar.gz -- cgit v1.2.3