Hi,

I am reading this thread with growing fascination, because I have the
feeling I am missing something, so can I summarize?

If I had a test, where I don't care about output and only about whther
exceptions are thrown or not I would normally write this:

@pytest.mark.parametrize(
    "req, exc", (
    ('foo', None),
    ('bar', None),
    ('BLARF', ValueError),
    ('PLONK', IndexError),
))
def test_something(self, arg, exc):
    if exc:
        with pytest.raises(exc):
            something(arg)
    else:
        something(arg)

So the new feature would save me two lines of code:

@pytest.mark.parametrize(
    "req, exc", (
    ('foo', None),
    ('bar', None),
    ('BLARF', ValueError),
    ('PLONK', IndexError),
))
def test_something(arg, exc):
    with pytest.raises(exc):
        something(arg)

... and this would be a bit harder to understand, because as Bruno found
out already, there are quite different expectations about what is supposed
to happen if I write pytest.raises(None).

Am I missing something?

I usually don't write tests like that anyway but rather tests where I
expect either a concrete value of a certain type or I expect an Exception
to be raised. E.g.

@pytest.mark.parametrize(
    "req, exp", (
    ('foo', True),
    ('bar', False),
    ('BLARF', ValueError),
    ('PLONK', IndexError),
))
def test_something(arg, exp):
    if not isinstance(exp, bool):
        with pytest.raises(exp):
            something(arg)
    else:
        assert something(arg) == exp

And there this feature would not help me anyway or one would have to make a
new bastard context manager like

@pytest.mark.parametrize(
    "req, exp", (
    ('foo', True),
    ('bar', False),
    ('BLARF', ValueError),
    ('PLONK', IndexError),
))
def test_something(arg, exp):
    with pytest.raises_or_returns_or_yields_or_whatever(exp):
        something(arg)

**shudder**

So I am not sure if this is worth implementing unless I am just not able to
grasp the real benfits.

Cheers,
Oliver
_______________________________________________
pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to