pytest-dev / pytest-asyncio

Asyncio support for pytest
https://pytest-asyncio.readthedocs.io
Apache License 2.0
1.43k stars 152 forks source link

Warn when passing scope as positional argument #812

Closed Cito closed 3 months ago

Cito commented 7 months ago

Recently I used pytest.mark.asyncio("session") instead of pytest.mark.asyncio(scope="session").

It took me quite a while to find out why the corresponding test was function scoped instead of session scoped.

It would be nice if either the scope could be passed as positional argument as well, or if there would be a helpful warning or error message in that case, instead of silently swallowing the positional argument.

I can contribute a PR for this feature if you let me know which exact behavior you prefer.

seifertm commented 4 months ago

Good finding!

Since the purpose of a positional argument is not immediately obvious from the pytest.mark.asyncio name, I think we should force a keyword argument here. I agree that issuing a warning when passing a positional argument is an improvement. If you can (still) find the time, I'd appreciate a PR for this.

Cito commented 4 months ago

Implemented in PR #886 now with tests for all such cases of mistakes in arguments.