-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
|
||
def test_no_error_when_scope_passed_as_sole_keyword_argument( | ||
pytester: pytest.Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio(scope="session") | ||
async def test_anything(): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest_subprocess() | ||
result.assert_outcomes(passed=1) | ||
result.stdout.no_fnmatch_line("*ValueError*") | ||
|
||
|
||
def test_error_when_scope_passed_as_positional_argument( | ||
pytester: pytest.Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio("session") | ||
async def test_anything(): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest_subprocess() | ||
result.assert_outcomes(errors=1) | ||
result.stdout.fnmatch_lines( | ||
["*ValueError: mark.asyncio accepts only a keyword argument*"] | ||
) | ||
|
||
|
||
def test_error_when_wrong_keyword_argument_is_passed( | ||
pytester: pytest.Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio(cope="session") | ||
async def test_anything(): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest_subprocess() | ||
result.assert_outcomes(errors=1) | ||
result.stdout.fnmatch_lines( | ||
["*ValueError: mark.asyncio accepts only a keyword argument 'scope'*"] | ||
) | ||
|
||
|
||
def test_error_when_additional_keyword_arguments_are_passed( | ||
pytester: pytest.Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio(scope="session", more="stuff") | ||
async def test_anything(): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest_subprocess() | ||
result.assert_outcomes(errors=1) | ||
result.stdout.fnmatch_lines( | ||
["*ValueError: mark.asyncio accepts only a keyword argument*"] | ||
) | ||
|
||
|
||
def test_error_when_an_invalid_scope_is_passed( | ||
pytester: pytest.Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio(scope="stuff") | ||
async def test_anything(): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest_subprocess() | ||
result.assert_outcomes(errors=1) | ||
result.stdout.fnmatch_lines(["*ValueError: Invalid scope 'stuff'*"]) |