pytest-dev / pytest-repeat

pytest plugin for repeating test execution
https://pypi.python.org/pypi/pytest-repeat/
Other
169 stars 27 forks source link

pytest-repeat crashes on doctest #41

Open brianmaissy opened 4 years ago

brianmaissy commented 4 years ago

on python 3.6.8, pytest 4.5.0, pytest-repeat 0.8.0

py.test --doctest-modules --count=2

    @pytest.fixture(autouse=True)
    def __pytest_repeat_step_number(request):
        if request.config.option.count > 1:
            try:
                return request.param
            except AttributeError:
>               if issubclass(request.cls, TestCase):
E               TypeError: issubclass() arg 1 must be a class

When the test is a doctest (request.node is a DoctestItem), request.cls is None.

I assume this can be fixed with an extra is not None in the condition on line 42: https://github.com/pytest-dev/pytest-repeat/blob/c74dd59ebceda1c7963cde1935a57c498bc565bf/pytest_repeat.py#L42

Happy to open a PR

brianmaissy commented 4 years ago

Hmm never mind it's a bit more complicated than that.

Looks like pytest_generate_tests isn't even called for doctest tests.

Let me know if you have any ideas, but if it's too complicated to be worth implementing I understand.

In any case fixing the issubclass call is probably a good idea, just so the error message would be more indicative:

pytest_repeat.UnexpectedError: This call couldn't work with pytest-repeat. Please consider raising an issue with your usage.

Maybe we could even check if it's a doctest and give an even more specific error.

blueyed commented 4 years ago

Related: https://github.com/pytest-dev/pytest/issues/5070 (I guess) Please also try master (https://github.com/pytest-dev/pytest-repeat/commit/c74dd59ebceda1c7963cde1935a57c498bc565bf might fix/improve the situation).

brianmaissy commented 4 years ago

on master it just fails silently, and doctests don't get run multiple times. its an improvement over crashing at least

nicoddemus commented 4 years ago

I assume this can be fixed with an extra is not None in the condition on line 42:

Seems like this makes sense either way, because param.cls might be None anytime a test is not defined in class.

okken commented 11 months ago

we should document that this doesn't work