pytest-repeat icon indicating copy to clipboard operation
pytest-repeat copied to clipboard

pytest-repeat crashes on doctest

Open brianmaissy opened this issue 6 years ago • 5 comments

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 avatar Nov 11 '19 08:11 brianmaissy

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.

brianmaissy avatar Nov 11 '19 08:11 brianmaissy

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).

blueyed avatar Nov 11 '19 13:11 blueyed

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

brianmaissy avatar Nov 12 '19 14:11 brianmaissy

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.

nicoddemus avatar Nov 13 '19 22:11 nicoddemus

we should document that this doesn't work

okken avatar Oct 06 '23 00:10 okken