diff --git a/README.rst b/README.rst index 2f282b5e..aa757b68 100644 --- a/README.rst +++ b/README.rst @@ -166,6 +166,8 @@ Changelog ~~~~~~~~~~~~~~~~~~~ - Add support for Python 3.9 - Abandon support for Python 3.5. If you still require support for Python 3.5, please use pytest-asyncio v0.14 or earlier. +- Set ``unused_tcp_port_factory`` fixture scope to 'session'. + `#163 `_ 0.14.0 (2020-06-24) ~~~~~~~~~~~~~~~~~~~ diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 4b7d6fd0..0f29be12 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -219,7 +219,7 @@ def unused_tcp_port(): return _unused_tcp_port() -@pytest.fixture +@pytest.fixture(scope='session') def unused_tcp_port_factory(): """A factory function, producing different unused TCP ports.""" produced = set() diff --git a/tests/conftest.py b/tests/conftest.py index 1ca63fe5..9e046123 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,3 +20,10 @@ async def just_a_sleep(): event_loop.run_until_complete(just_a_sleep()) assert counter == 2 + + +@pytest.fixture(scope='session', name='factory_involving_factories') +def factory_involving_factories_fixture(unused_tcp_port_factory): + def factory(): + return unused_tcp_port_factory() + return factory diff --git a/tests/test_dependent_fixtures.py b/tests/test_dependent_fixtures.py index db2252b2..2876255b 100644 --- a/tests/test_dependent_fixtures.py +++ b/tests/test_dependent_fixtures.py @@ -6,3 +6,8 @@ async def test_dependent_fixture(dependent_fixture): """Test a dependent fixture.""" await asyncio.sleep(0.1) + + +@pytest.mark.asyncio +async def test_factory_involving_factories(factory_involving_factories): + factory_involving_factories()