You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a way to automatically treat all async tests as trio tests #9
We don't want to do this by default, because then we get into the situation where all the different pytest-{asyncio,trio,curio,...} plugins fight over which tests are theirs. And we want to preserve the option to mark individual tests with @pytest.mark.trio, for projects that want to use multiple pytest-* plugins at the same time.
But for the common case of a project that uses only trio, there should be some way to opt-in to automatic detection of async tests as trio tests.
An option in pytest.ini is one obvious thing. We should also give a way for conftest.py to opt-in directly, for the use of projects that ship their tests along with their source code but can't easily ship a pytest.ini.
What would be really neat was if we could limit the conftest.py opt-in to the subdirectory that conftest.py applies to. I'm not sure if there's a way to do that.
I guess one option for marking things in conftest would be to tell people to write
frompytest_trio.automarkimport*
where pytest_trio/automark.py contains a plugin hook that sniffs test to see if they're async, and if so then automatically applies the trio marker.
This is evil and magical: the idea is to exploit pytest's magic where every conftest.py file is automatically treated as a pytest plugin that's applied only to the tests inside the same directory as that conftest.py. And the effects of a pytest plugin are determined by the contents of its namespace. So if we import a hook function, then that hook function becomes part of this "conftest plugin", and is applied where-ever the conftest is in scope.
Activity
njsmith commentedon Dec 9, 2017
I guess one option for marking things in conftest would be to tell people to write
where
pytest_trio/automark.pycontains a plugin hook that sniffs test to see if they're async, and if so then automatically applies thetriomarker.This is evil and magical: the idea is to exploit pytest's magic where every
conftest.pyfile is automatically treated as a pytest plugin that's applied only to the tests inside the same directory as thatconftest.py. And the effects of a pytest plugin are determined by the contents of its namespace. So if we import a hook function, then that hook function becomes part of this "conftest plugin", and is applied where-ever the conftest is in scope.Implement Trio mode
Implement Trio mode