Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid to use pytest.mark.xfail without a raises= argument #142

Open
sobolevn opened this issue Aug 18, 2021 · 3 comments
Open

Forbid to use pytest.mark.xfail without a raises= argument #142

sobolevn opened this issue Aug 18, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@sobolevn
Copy link

sobolevn commented Aug 18, 2021

Today I got hit by a xfail problem. My module was decorated with pytest.mark.xfail, because I wanted to test an explicit test failure in my plugin: https://github.com/dry-python/returns/blob/2223f03a2dbb96d4cd273fb41ad5c26331d9eef8/tests/test_contrib/test_hypothesis/test_laws/test_wrong_custom_type_with_init.py#L10

But, under some condition, I've noticed that sometimes it was failing due to an unknown reason.
It was really hard to find, because this test was passing for a year now.

So, my idea is to:

  • Allow pytest.mark.xfailure(raises=ExceptionType)
  • Forbid pytest.mark.xfailure or ``pytest.mark.xfailure()`

Docs: https://docs.pytest.org/en/6.2.x/skipping.html#raises-parameter

It hides errors 😞

@sobolevn sobolevn added the enhancement New feature or request label Aug 18, 2021
@djmattyg007
Copy link

If you’re testing know failure conditions, it sounds like you should be using pytest.raises().

@sobolevn
Copy link
Author

No, I should not 🙂

Please, take a look at my sample:

pytestmark = pytest.mark.xfail

_ValueType = TypeVar('_ValueType')
_NewValueType = TypeVar('_NewValueType')


class _Wrapper(
    BaseContainer,
    SupportsKind1['_Wrapper', _ValueType],
    mappable.Mappable1[_ValueType],
):
    _inner_value: _ValueType

    def __init__(self, inner_value: _ValueType) -> None:
        super().__init__(inner_value)

    def map(
        self,
        function: Callable[[_ValueType], _NewValueType],
    ) -> '_Wrapper[_NewValueType]':
        return _Wrapper(
            'wrong-{0}'.format(function(self._inner_value)),  # type: ignore
        )


check_all_laws(_Wrapper, use_init=True)

There's no place for pytest.raises.

@m-burst
Copy link
Owner

m-burst commented Apr 18, 2022

In any scenario, if we expect a test to fail, it is best to pin how exactly we expect it to fail, so that it will be noticed if something changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants