GithubHelp home page GithubHelp logo

bjoluc / pytest-reraise Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 4.0 88 KB

Make multi-threaded pytest test cases fail when they should

License: MIT License

Python 100.00%
pytest plugin threads exception assert catch raise re-raise

pytest-reraise's People

Contributors

bjoluc avatar jcpunk avatar michelhe avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pytest-reraise's Issues

How to make assertions about captured exceptions?

The following example from the README isn't very useful since once the AssertionError is raised in run(), the rest isn't executed.

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

Instead I have to perform

import pytest
from threading import Thread

@pytest.mark.xfail(strict=True, raises=ValueError)
def test_assert(reraise):

    def run():
        with reraise:
            raise ValueError

    t = Thread(target=run)
    t.start()
    t.join()

    # This won't be evaluated 
    assert type(reraise.exception) is 5

I feel I'm missing something.

It's great that the exception is raised to the main thread, but you cannot easily check what type it is without using @pytest.mark.xfail(strict=True, raises=ValueError)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.