test_ok2/testing/python
Ran Benita 24dcc76495 Use a hack to make typing of pytest.fail.Exception & co work
Mypy currently is unable to handle assigning attributes on function:
https://github.com/python/mypy/issues/2087.
pytest uses this for the outcome exceptions -- `pytest.fail.Exception`,
`pytest.exit.Exception` etc, and this is the canonical name by which they
are referred.

Initially we started working around this with type: ignores, and later
by switching e.g. `pytest.fail.Exception` with the direct exception
`Failed`. But this causes a lot of churn and is not as nice. And I also
found that some code relies on it, in skipping.py:

    def pytest_configure(config):
        if config.option.runxfail:
            # yay a hack
            import pytest

            old = pytest.xfail
            config._cleanup.append(lambda: setattr(pytest, "xfail", old))

            def nop(*args, **kwargs):
                pass

            nop.Exception = xfail.Exception
            setattr(pytest, "xfail", nop)
        ...

So it seems better to support it. Use a hack to make it work. The rest
of the commit rolls back all of the workarounds we added up to now.

`pytest.raises.Exception` also exists, but it's not used much so I kept
it as-is for now.

Hopefully in the future mypy supports this and this ugliness can be
removed.
2020-02-18 23:17:27 +02:00
..
approx.py tests: test_unicode_plus_minus: use unicode sign directly (#6727) 2020-02-14 02:16:25 +01:00
collect.py Use a hack to make typing of pytest.fail.Exception & co work 2020-02-18 23:17:27 +02:00
fixtures.py Fix unguarded `==` comparison in fixtures. (#6541) 2020-01-28 20:54:14 -03:00
integration.py deprecate direct node construction and introduce Node.from_parent 2019-11-23 21:54:11 +01:00
metafunc.py Use a hack to make typing of pytest.fail.Exception & co work 2020-02-18 23:17:27 +02:00
raises.py Remove "pragma: no cover" comments 2020-01-14 09:15:36 +01:00
show_fixtures_per_test.py Use new no-match functions to replace previous idiom 2019-10-06 18:05:24 -03:00