forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use inspect to properly detect generators. Fixes pytest-dev#2129
- Loading branch information
Showing
5 changed files
with
56 additions
and
5 deletions.
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,7 @@ | ||
import sys | ||
|
||
collect_ignore = [] | ||
if sys.version_info[0] < 3: | ||
collect_ignore.append("test_compat_3.py") | ||
if sys.version_info < (3, 5): | ||
collect_ignore.append("test_compat_35.py") |
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,12 @@ | ||
from _pytest.compat import is_generator | ||
|
||
|
||
def test_is_generator(): | ||
def zap(): | ||
yield | ||
|
||
def foo(): | ||
pass | ||
|
||
assert is_generator(zap) | ||
assert not is_generator(foo) |
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,15 @@ | ||
import pytest | ||
from _pytest.compat import is_generator | ||
try: | ||
import asyncio | ||
except ImportError: | ||
asyncio = None | ||
|
||
|
||
@pytest.mark.skipif(asyncio is None, reason='asyncio is not installed') | ||
def test_is_generator(): | ||
@asyncio.coroutine | ||
def baz(): | ||
yield from [1,2,3] | ||
|
||
assert not is_generator(baz) |
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,12 @@ | ||
from _pytest.compat import is_generator | ||
|
||
|
||
def test_is_generator_py35(): | ||
async def foo(): | ||
await foo() | ||
|
||
async def bar(): | ||
pass | ||
|
||
assert not is_generator(foo) | ||
assert not is_generator(bar) |