Lemmons/pytest-raises

No test case: parameterization of exceptions via pytest.param, passing in 'marks='

Closed this issue · 3 comments

As I was going through the tests within this project, I noticed there are no tests for parameterization of exceptions via pytest.param, passing in 'marks='.

A little background:
In the past, it has been an acceptable practice to pass pytest.mark.raises directly into your parametrize list if you want to parametrize a test that raises an expected exception. But now, if you are using a newer version of pytest, you will in fact get a deprecation warning.

RemovedInPytest4Warning: Applying marks directly to parameters is deprecated, please use pytest.param(..., marks=...) instead.

Although the tests don't technically fail, it is annoying to get a bunch of these warnings, especially if you are using a lot of parametrization in your test suite.
Here is an example of the idiom to which one should probably migrate:

import pytest

class SomeException(Exception):
    pass

@pytest.mark.parametrize(
    'error',
    [None,
     pytest.param(SomeException('the message'),
                  marks=pytest.mark.raises(SomeException(),
                                           exception=SomeException)),
     ])
def test_mark_raises(error):
    if error:
        raise error

And although a bit more verbose, it conforms to the newer pytest, and the warnings go away.

To be clear, pytest-raises version 0.10 does support this and it is working fine for me. I just didn't see a pytest which documents and verifies this specific feature within the project.

Unfortunately, with the release of pytest 4, this is now a breaking issue 😭. Ideally I think there could be an easier/less verbose way of passing in the mark with a keyword argument.
I've opened an issue with them though - we'll see what they say: pytest-dev/pytest#4395

I'm totally up for changing the tests, but, unfortunately, I don't really have time right now to do this. I will gladly work with anyone who wants to create a pr for this issue though.

This issue is really a pain in the ass now. Sorry, but it will take even more time for somebody who does not know your code and/or pytest framework development internals to achieve the same goal.