diff --git a/setup.cfg b/setup.cfg index 9ade7832161..d10e8650e92 100644 --- a/setup.cfg +++ b/setup.cfg @@ -118,6 +118,10 @@ tests = flake8>=3.0.0 mypy>=0.910,<1.9 # https://github.com/pytest-dev/pytest-asyncio/issues/706 + # BACK COMAPAT: pytest-asyncio 0.21.2 + # FROM: python 3 + # TO: python 3.7 + # URL: https://github.com/cylc/cylc-flow/pull/6726 pytest-asyncio>=0.21.2,!=0.23.* pytest-cov>=2.8.0 pytest-xdist>=2 diff --git a/tests/conftest.py b/tests/conftest.py index d4a86805a2c..b972099c704 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,6 +21,7 @@ from typing import List, Optional, Tuple import pytest +import pytest_asyncio from cylc.flow import LOG, flags from cylc.flow.cfgspec.glbl_cfg import glbl_cfg @@ -40,7 +41,7 @@ def before_each(): GraphNodeParser.get_inst().clear() -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_monkeypatch(): """A module-scoped version of the monkeypatch fixture.""" from _pytest.monkeypatch import MonkeyPatch @@ -160,7 +161,7 @@ def _log_scan(log, items): return _log_scan -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def port_range(): return glbl_cfg().get(['scheduler', 'run hosts', 'ports']) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 89987f6665d..95f691a3712 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -30,6 +30,7 @@ ) import pytest +import pytest_asyncio from cylc.flow.config import WorkflowConfig from cylc.flow.id import Tokens @@ -112,7 +113,7 @@ def _pytest_passed(request: pytest.FixtureRequest) -> bool: )) -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def run_dir(): """The cylc run directory for this host.""" path = Path(get_cylc_run_dir()) @@ -120,7 +121,7 @@ def run_dir(): yield path -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def ses_test_dir(request, run_dir): """The root run dir for test flows in this test session.""" timestamp = get_current_time_string(use_basic_format=True) @@ -131,7 +132,7 @@ def ses_test_dir(request, run_dir): _rm_if_empty(path) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_test_dir(request, ses_test_dir): """The root run dir for test flows in this test module.""" path = Path( @@ -163,7 +164,7 @@ def test_dir(request, mod_test_dir): _rm_if_empty(path) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_flow(run_dir, mod_test_dir): """A function for creating module-level flows.""" yield partial(_make_flow, run_dir, mod_test_dir) @@ -175,7 +176,7 @@ def flow(run_dir, test_dir): yield partial(_make_flow, run_dir, test_dir) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_scheduler(): """Return a Scheduler object for a flow. @@ -197,7 +198,7 @@ def scheduler(): yield _scheduler -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_start(): """Start a scheduler but don't set it running (module scope).""" return partial(_start_flow, None) @@ -209,7 +210,7 @@ def start(caplog: pytest.LogCaptureFixture): return partial(_start_flow, caplog) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_run(): """Start a scheduler and set it running (module scope).""" return partial(_run_flow, None) @@ -235,7 +236,7 @@ def one_conf(): } -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_one_conf(): return { 'scheduler': { @@ -257,36 +258,37 @@ def one(one_conf, flow, scheduler): return schd -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_one(mod_one_conf, mod_flow, mod_scheduler): id_ = mod_flow(mod_one_conf) schd = mod_scheduler(id_) return schd -@pytest.fixture(scope='module') -def event_loop(): - """This fixture defines the event loop used for each test. - - The default scoping for this fixture is "function" which means that all - async fixtures must have "function" scoping. - - Defining `event_loop` as a module scoped fixture opens the door to - module scoped fixtures but means all tests in a module will run in the same - event loop. This is fine, it's actually an efficiency win but also - something to be aware of. - - See: https://github.com/pytest-dev/pytest-asyncio/issues/171 - - """ - loop = asyncio.get_event_loop_policy().new_event_loop() - yield loop - # gracefully exit async generators - loop.run_until_complete(loop.shutdown_asyncgens()) - # cancel any tasks still running in this event loop - for task in asyncio.all_tasks(loop): - task.cancel() - loop.close() +if pytest_asyncio.__version__.startswith('0.21'): + # BACK COMPAT: event_loop + # FROM: python 3 + # TO: python 3.7 + # URL: https://github.com/cylc/cylc-flow/pull/6726 + @pytest_asyncio.fixture(scope='module') + def event_loop(): + """This fixture defines the event loop used for each test. + The default scoping for this fixture is "function" which means that all + async fixtures must have "function" scoping. + Defining `event_loop` as a module scoped fixture opens the door to + module scoped fixtures but means all tests in a module will run in the + same event loop. This is fine, it's actually an efficiency win but also + something to be aware of. + See: https://github.com/pytest-dev/pytest-asyncio/issues/171 + """ + loop = asyncio.get_event_loop_policy().new_event_loop() + yield loop + # gracefully exit async generators + loop.run_until_complete(loop.shutdown_asyncgens()) + # cancel any tasks still running in this event loop + for task in asyncio.all_tasks(loop): + task.cancel() + loop.close() @pytest.fixture @@ -382,7 +384,7 @@ def _validate(id_: Union[str, Path], **kwargs) -> WorkflowConfig: return _validate -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_validate(run_dir): """Provides a function for validating workflow configurations. @@ -465,7 +467,7 @@ def run_job_cmd( return _disable_polling -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_workflow_source(mod_flow, tmp_path_factory): """Create a workflow source directory. @@ -686,7 +688,7 @@ def complete(): return _complete -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_complete(): return _complete diff --git a/tests/integration/network/test_client.py b/tests/integration/network/test_client.py index b02df549d6a..af4c18aa6b9 100644 --- a/tests/integration/network/test_client.py +++ b/tests/integration/network/test_client.py @@ -15,16 +15,19 @@ # along with this program. If not, see . """Test cylc.flow.client.WorkflowRuntimeClient.""" + import json from unittest.mock import Mock + import pytest +import pytest_asyncio from cylc.flow.exceptions import ClientError from cylc.flow.network.client import WorkflowRuntimeClient from cylc.flow.network.server import PB_METHOD_MAP -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def harness(mod_flow, mod_scheduler, mod_run, mod_one_conf): id_ = mod_flow(mod_one_conf) schd = mod_scheduler(id_) diff --git a/tests/integration/network/test_graphql.py b/tests/integration/network/test_graphql.py index 6d8f4f63ca3..76af22b9e90 100644 --- a/tests/integration/network/test_graphql.py +++ b/tests/integration/network/test_graphql.py @@ -16,9 +16,11 @@ """Test the top-level (root) GraphQL queries.""" -import pytest from typing import TYPE_CHECKING +import pytest +import pytest_asyncio + from cylc.flow.id import Tokens from cylc.flow.network.client import WorkflowRuntimeClient @@ -68,7 +70,7 @@ def job_db_row(): ] -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def harness(mod_flow, mod_scheduler, mod_run): flow_def = { 'scheduler': { diff --git a/tests/integration/network/test_resolvers.py b/tests/integration/network/test_resolvers.py index 251d01e0ac4..83fd36097b3 100644 --- a/tests/integration/network/test_resolvers.py +++ b/tests/integration/network/test_resolvers.py @@ -19,6 +19,7 @@ from unittest.mock import Mock import pytest +import pytest_asyncio from cylc.flow.data_store_mgr import EDGES, TASK_PROXIES from cylc.flow.id import Tokens @@ -50,7 +51,7 @@ def node_args(): } -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def mock_flow( mod_flow: Callable[..., str], mod_scheduler: Callable[..., Scheduler], diff --git a/tests/integration/network/test_scan.py b/tests/integration/network/test_scan.py index 26dba076514..f65a4d80d82 100644 --- a/tests/integration/network/test_scan.py +++ b/tests/integration/network/test_scan.py @@ -23,6 +23,7 @@ from typing import List import pytest +import pytest_asyncio from cylc.flow.network.scan import ( filter_name, @@ -81,7 +82,7 @@ def make_src(name): make_src(name) -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def sample_run_dir(): tmp_path = Path(TemporaryDirectory().name) tmp_path.mkdir() @@ -111,7 +112,7 @@ def badly_messed_up_cylc_run_dir( return tmp_path -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def run_dir_with_symlinks(): tmp_path = Path(TemporaryDirectory().name) tmp_path.mkdir() @@ -133,7 +134,7 @@ def run_dir_with_symlinks(): rmtree(tmp_path) -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def run_dir_with_nasty_symlinks(): tmp_path = Path(TemporaryDirectory().name) tmp_path.mkdir() @@ -148,7 +149,7 @@ def run_dir_with_nasty_symlinks(): rmtree(tmp_path) -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def nested_dir(): tmp_path = Path(TemporaryDirectory().name) tmp_path.mkdir() diff --git a/tests/integration/network/test_server.py b/tests/integration/network/test_server.py index 7df277c66dc..e5f01e82a17 100644 --- a/tests/integration/network/test_server.py +++ b/tests/integration/network/test_server.py @@ -19,6 +19,7 @@ from typing import Callable import pytest +import pytest_asyncio from cylc.flow import __version__ as CYLC_VERSION from cylc.flow.network.server import PB_METHOD_MAP @@ -31,7 +32,7 @@ from async_timeout import timeout -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def myflow(mod_flow, mod_scheduler, mod_run, mod_one_conf): id_ = mod_flow(mod_one_conf) schd = mod_scheduler(id_) diff --git a/tests/integration/network/test_zmq.py b/tests/integration/network/test_zmq.py index 24c8db6d9b0..36c1503dac1 100644 --- a/tests/integration/network/test_zmq.py +++ b/tests/integration/network/test_zmq.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import zmq from cylc.flow.exceptions import CylcError @@ -23,7 +24,7 @@ from .key_setup import setup_keys -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def myflow(mod_flow, mod_one_conf): return mod_flow(mod_one_conf) diff --git a/tests/integration/run_modes/test_simulation.py b/tests/integration/run_modes/test_simulation.py index aee9f1585d0..ff13d015191 100644 --- a/tests/integration/run_modes/test_simulation.py +++ b/tests/integration/run_modes/test_simulation.py @@ -18,8 +18,10 @@ import logging from pathlib import Path + import pytest from pytest import param +import pytest_asyncio from cylc.flow import commands from cylc.flow.cycling.iso8601 import ISO8601Point @@ -88,7 +90,7 @@ def _run_simjob(schd, point, task): return _run_simjob -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def sim_time_check_setup( mod_flow, mod_scheduler, mod_start, mod_one_conf, ): diff --git a/tests/integration/scripts/test_list.py b/tests/integration/scripts/test_list.py index 08fa3706b58..55509db0669 100644 --- a/tests/integration/scripts/test_list.py +++ b/tests/integration/scripts/test_list.py @@ -17,6 +17,7 @@ """Test the "cylc list" command.""" import pytest +import pytest_asyncio from cylc.flow.exceptions import InputError from cylc.flow.option_parsers import Options @@ -29,7 +30,7 @@ ListOptions = Options(get_option_parser()) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def cylc_list(mod_flow, mod_scheduler, mod_start): id_ = mod_flow( { diff --git a/tests/integration/scripts/test_show.py b/tests/integration/scripts/test_show.py index e4490164752..a7513c58a07 100644 --- a/tests/integration/scripts/test_show.py +++ b/tests/integration/scripts/test_show.py @@ -15,11 +15,12 @@ # along with this program. If not, see . import json -import pytest import re from types import SimpleNamespace from colorama import init as colour_init +import pytest +import pytest_asyncio from cylc.flow.id import Tokens from cylc.flow.scripts.show import ( @@ -31,7 +32,7 @@ RE_STATE = re.compile('state:.*') -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_my_conf(): """A workflow configuration with some workflow metadata.""" return { @@ -70,7 +71,7 @@ def mod_my_conf(): } -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def mod_my_schd(mod_flow, mod_scheduler, mod_start, mod_my_conf): """A "started" workflow.""" id_ = mod_flow(mod_my_conf) diff --git a/tests/integration/test_data_store_mgr.py b/tests/integration/test_data_store_mgr.py index 4d0d5f39620..16057876adf 100644 --- a/tests/integration/test_data_store_mgr.py +++ b/tests/integration/test_data_store_mgr.py @@ -22,6 +22,7 @@ ) import pytest +import pytest_asyncio from cylc.flow.data_messages_pb2 import ( PbPrerequisite, @@ -116,7 +117,7 @@ def get_pb_prereqs(schd: 'Scheduler') -> 'List[PbPrerequisite]': ] -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def harness(mod_flow, mod_scheduler, mod_start): flow_def = { 'scheduler': { diff --git a/tests/integration/test_dbstatecheck.py b/tests/integration/test_dbstatecheck.py index 56363e7ff7c..c48947a66c9 100644 --- a/tests/integration/test_dbstatecheck.py +++ b/tests/integration/test_dbstatecheck.py @@ -16,13 +16,13 @@ """Tests for the backend method of workflow_state""" -import pytest +import pytest_asyncio from cylc.flow.dbstatecheck import CylcWorkflowDBChecker from cylc.flow.scheduler import Scheduler -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def checker( mod_flow, mod_scheduler, mod_run, mod_complete ): diff --git a/tests/integration/test_examples.py b/tests/integration/test_examples.py index a0d15ee7289..59f449ceb51 100644 --- a/tests/integration/test_examples.py +++ b/tests/integration/test_examples.py @@ -25,6 +25,7 @@ from pathlib import Path import pytest +import pytest_asyncio from cylc.flow import __version__ from cylc.flow.scheduler import Scheduler @@ -173,7 +174,7 @@ def killer(): assert one.server.replier.socket.closed -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def myflow(mod_flow, mod_scheduler, mod_one_conf): """You can save setup/teardown time by reusing fixtures diff --git a/tests/integration/test_get_old_tvars.py b/tests/integration/test_get_old_tvars.py index 2053db26c30..3ebe60a66d2 100644 --- a/tests/integration/test_get_old_tvars.py +++ b/tests/integration/test_get_old_tvars.py @@ -16,6 +16,7 @@ import pytest from pytest import param +import pytest_asyncio from cylc.flow.option_parsers import Options @@ -41,7 +42,7 @@ ) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def _setup(mod_scheduler, mod_flow): """Provide an installed flow with a database to try assorted simple Cylc scripts against. diff --git a/tests/integration/test_id_cli.py b/tests/integration/test_id_cli.py index 950bad7bb1a..a2782b20e60 100644 --- a/tests/integration/test_id_cli.py +++ b/tests/integration/test_id_cli.py @@ -17,13 +17,13 @@ """Some integration tests running on live workflows to test filtering properly. """ -import pytest +import pytest_asyncio from cylc.flow.pathutil import get_cylc_run_dir from cylc.flow.id_cli import parse_ids_async -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def harness( mod_run, mod_scheduler, diff --git a/tests/integration/test_optional_outputs.py b/tests/integration/test_optional_outputs.py index 04cabdeceb2..46715ac1513 100644 --- a/tests/integration/test_optional_outputs.py +++ b/tests/integration/test_optional_outputs.py @@ -25,6 +25,7 @@ from typing import TYPE_CHECKING import pytest +import pytest_asyncio from cylc.flow.cycling.integer import IntegerPoint from cylc.flow.cycling.iso8601 import ISO8601Point @@ -243,7 +244,7 @@ async def test_expire_orthogonality(flow, scheduler, start): assert not schd.pool.is_stalled() -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def implicit_completion_config(mod_flow, mod_validate): id_ = mod_flow({ 'scheduling': { diff --git a/tests/integration/test_scan_api.py b/tests/integration/test_scan_api.py index 71d83124f77..a9c8d3e741c 100644 --- a/tests/integration/test_scan_api.py +++ b/tests/integration/test_scan_api.py @@ -22,7 +22,7 @@ rmtree ) -import pytest +import pytest_asyncio from cylc.flow.scripts.scan import ( main, @@ -36,7 +36,7 @@ ) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def flows(mod_flow, mod_scheduler, mod_run, mod_one_conf): """Three workflows in different states. diff --git a/tests/integration/test_task_pool.py b/tests/integration/test_task_pool.py index b1cd6187e01..6e0c2cd2f02 100644 --- a/tests/integration/test_task_pool.py +++ b/tests/integration/test_task_pool.py @@ -28,6 +28,7 @@ import pytest from pytest import param +import pytest_asyncio from cylc.flow import ( CYLC_LOG, @@ -130,7 +131,7 @@ def assert_expected_log( return logged_messages -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def mod_example_flow( mod_flow: Callable, mod_scheduler: Callable, mod_run: Callable ) -> AsyncGenerator['Scheduler', None]: @@ -166,7 +167,7 @@ async def example_flow( yield schd -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def mod_example_flow_2( mod_flow: Callable, mod_scheduler: Callable, mod_run: Callable ) -> AsyncGenerator['Scheduler', None]: @@ -1865,7 +1866,7 @@ async def test_runahead_future_trigger( assert str(schd.pool.runahead_limit_point) == '20010104' -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def mod_blah( mod_flow: Callable, mod_scheduler: Callable, mod_run: Callable ) -> 'Scheduler': diff --git a/tests/integration/test_workflow_files.py b/tests/integration/test_workflow_files.py index dcab9d261ac..a5bfd19e808 100644 --- a/tests/integration/test_workflow_files.py +++ b/tests/integration/test_workflow_files.py @@ -22,6 +22,7 @@ from uuid import uuid4 import pytest +import pytest_asyncio from cylc.flow import CYLC_LOG from cylc.flow.exceptions import ( @@ -39,7 +40,7 @@ ) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def myflow(mod_flow, mod_scheduler, mod_run, mod_one_conf): id_ = mod_flow(mod_one_conf) schd = mod_scheduler(id_) diff --git a/tests/integration/tui/test_logs.py b/tests/integration/tui/test_logs.py index bc66bc6be10..28cbac4a1ee 100644 --- a/tests/integration/tui/test_logs.py +++ b/tests/integration/tui/test_logs.py @@ -29,6 +29,7 @@ from cylc.flow.tui.data import _get_log import pytest +import pytest_asyncio if TYPE_CHECKING: from cylc.flow.id import Tokens @@ -51,7 +52,7 @@ def get_job_log(tokens: 'Tokens', suffix: str) -> Path: )) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def standarise_host_and_path(mod_monkeypatch): """Replace variable content in the log view. @@ -113,7 +114,7 @@ async def _wait_log_loaded(tries: int = 25, delay: float = 0.1): return _wait_log_loaded -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') async def workflow( mod_flow, mod_scheduler, mod_start, standarise_host_and_path ): diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index b2415148ebc..4dedcbdd0c7 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -29,6 +29,7 @@ ) import pytest +import pytest_asyncio from cylc.flow.cycling.iso8601 import init as iso8601_init from cylc.flow.cycling.loader import ( @@ -126,7 +127,7 @@ def tmp_run_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): return _tmp_run_dir(tmp_path, monkeypatch) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_tmp_run_dir(tmp_path_factory: pytest.TempPathFactory): """Module-scoped version of tmp_run_dir()""" tmp_path = tmp_path_factory.getbasetemp() @@ -161,7 +162,7 @@ def tmp_src_dir(tmp_path: Path): return _tmp_src_dir(tmp_path) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_tmp_src_dir(tmp_path_factory: pytest.TempPathFactory): """Module-scoped version of tmp_src_dir()""" tmp_path = tmp_path_factory.getbasetemp() @@ -247,6 +248,6 @@ def tmp_flow_config(tmp_run_dir: Callable): return _tmp_flow_config(tmp_run_dir) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def mod_tmp_flow_config(mod_tmp_run_dir: Callable): return _tmp_flow_config(mod_tmp_run_dir) diff --git a/tests/unit/parsec/test_config_node.py b/tests/unit/parsec/test_config_node.py index 807967f6cb1..d5396820791 100644 --- a/tests/unit/parsec/test_config_node.py +++ b/tests/unit/parsec/test_config_node.py @@ -14,12 +14,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pytest +import pytest_asyncio from cylc.flow.parsec.config import ConfigNode as Conf -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def basic_config(): """A basic config with a file, section and setting.""" with Conf('file.cylc') as file_: @@ -60,7 +60,7 @@ def test_config_repr(basic_config): assert repr(setting) == 'file.cylc[section]setting' -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def many_setting(): """A config containing a user-definable setting.""" with Conf('file.cylc') as file_: @@ -77,7 +77,7 @@ def test_many_setting(many_setting): assert repr(setting) == 'file.cylc|' -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def many_section(): """A config containing a user-definable section.""" with Conf('file.cylc') as file_: @@ -98,7 +98,7 @@ def test_many_section(many_section): assert repr(setting) == 'file.cylc[
]setting' -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def meta_conf(): """A config with an inherited section.""" with Conf('Foo') as spec: diff --git a/tests/unit/post_install/test_log_vc_info.py b/tests/unit/post_install/test_log_vc_info.py index 67e204db747..e6a740b0804 100644 --- a/tests/unit/post_install/test_log_vc_info.py +++ b/tests/unit/post_install/test_log_vc_info.py @@ -17,14 +17,16 @@ import json import logging from pathlib import Path -import pytest -from pytest import MonkeyPatch, TempPathFactory -from secrets import token_hex import shutil import subprocess from typing import Any, Callable, Tuple from unittest.mock import Mock +import pytest +from pytest import MonkeyPatch, TempPathFactory +import pytest_asyncio +from secrets import token_hex + from cylc.flow.install_plugins.log_vc_info import ( INFO_FILENAME, VCSNotInstalledError, @@ -64,7 +66,7 @@ ) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def git_source_repo(tmp_path_factory: TempPathFactory) -> Tuple[str, str]: """Init a git repo for a workflow source dir. @@ -93,7 +95,7 @@ def git_source_repo(tmp_path_factory: TempPathFactory) -> Tuple[str, str]: return (str(source_dir), commit_sha) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def svn_source_repo(tmp_path_factory: TempPathFactory) -> Tuple[str, str, str]: """Init an svn repo & working copy for a workflow source dir. diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 2ff6922d723..f1514a62266 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -17,13 +17,16 @@ import os from optparse import Values from typing import ( - TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type) -import pytest + TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type +) import logging from textwrap import dedent from types import SimpleNamespace from contextlib import suppress +import pytest +import pytest_asyncio + from cylc.flow import CYLC_LOG from cylc.flow.config import WorkflowConfig from cylc.flow.cycling import loader @@ -1517,7 +1520,7 @@ def test_check_for_owner(runtime_cfg): assert WorkflowConfig.check_for_owner(runtime_cfg) is None -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def awe_config(mod_tmp_flow_config: Callable) -> WorkflowConfig: """Return a workflow config object.""" id_ = 'awe' diff --git a/tests/unit/test_id_cli.py b/tests/unit/test_id_cli.py index c68c93c263d..1d0c7180536 100644 --- a/tests/unit/test_id_cli.py +++ b/tests/unit/test_id_cli.py @@ -17,9 +17,11 @@ import logging import os from pathlib import Path -import pytest from shutil import copytree, rmtree +import pytest +import pytest_asyncio + from cylc.flow import CYLC_LOG from cylc.flow.async_util import pipe from cylc.flow.exceptions import InputError, WorkflowFilesError @@ -42,7 +44,7 @@ def mock_exists(monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr('pathlib.Path.exists', lambda *a, **k: True) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def abc_src_dir(tmp_path_factory): """Src dir containing three workflows, a, b & c.""" cwd_before = Path.cwd() diff --git a/tests/unit/test_option_parsers.py b/tests/unit/test_option_parsers.py index 5a37d0bdc3d..66749d408fb 100644 --- a/tests/unit/test_option_parsers.py +++ b/tests/unit/test_option_parsers.py @@ -22,6 +22,7 @@ import pytest from pytest import param +import pytest_asyncio import cylc.flow.flags from cylc.flow.option_parsers import ( @@ -37,7 +38,7 @@ USEIF = 'useif' -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def parser(): return COP( USAGE_WITH_COMMENT, diff --git a/tests/unit/test_templatevars.py b/tests/unit/test_templatevars.py index dafcde7b102..d9e06697eaa 100644 --- a/tests/unit/test_templatevars.py +++ b/tests/unit/test_templatevars.py @@ -15,11 +15,13 @@ # along with this program. If not, see . from pathlib import Path -import pytest -from pytest import param import tempfile import unittest +import pytest +from pytest import param +import pytest_asyncio + from cylc.flow import __version__ as cylc_version from cylc.flow.exceptions import ServiceFileError, InputError from cylc.flow.rundb import CylcWorkflowDAO @@ -110,7 +112,7 @@ def test_load_template_vars_from_string_and_file_2(self): self.assertEqual(expected, load_template_vars(template_vars=pairs)) -@pytest.fixture(scope='module') +@pytest_asyncio.fixture(scope='module') def _setup_db(tmp_path_factory): tmp_path: Path = tmp_path_factory.mktemp('test_get_old_tvars') logfolder = tmp_path / WorkflowFiles.LogDir.DIRNAME