From c93d119873863897a07d0fc6d48742d7337d5cde Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 22 May 2023 12:00:41 -0400 Subject: [PATCH] Move tmpdir creation into separate fixture Since `.config.load()` was changed to not touch conf files by default (without explicitly setting `touch_if_dne: bool`), this ensures both the global module value is set and the `brokers.toml` file exists before every test. --- tests/conftest.py | 49 +++++++++++++++++++++++++++++++++------------ tests/test_feeds.py | 5 ++--- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d5b0d697..364be44a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,6 @@ import os from pathlib import Path import pytest -import pytest_trio import tractor from piker import ( config, @@ -149,19 +148,49 @@ async def _open_test_pikerd( @pytest.fixture -def open_test_pikerd( - request: pytest.FixtureRequest, +def tmpconfdir( tmp_path: Path, - loglevel: str, -): +) -> Path: + ''' + Ensure the `brokers.toml` file for the test run exists + since we changed it to not touch files by default. + + Here we override the default (in the user dir) and + set the global module var the same as we do inside + the `tmpconfdir` fixture. + + ''' tmpconfdir: Path = tmp_path / '_testing' tmpconfdir.mkdir() - tmpconfdir_str: str = str(tmpconfdir) + # touch the `brokers.toml` file since it won't + # exist in the tmp test dir by default! # override config dir in the root actor (aka # this top level testing process). from piker import config - config._config_dir = tmpconfdir + config._config_dir: Path = tmpconfdir + conf, path = config.load( + touch_if_dne=True, + ) + + return tmpconfdir + + # NOTE: the `tmp_dir` fixture will wipe any files older then 3 test + # sessions by default: + # https://docs.pytest.org/en/6.2.x/tmpdir.html#the-default-base-temporary-directory + # BUT, if we wanted to always wipe conf dir and all contained files, + # rmtree(str(tmp_path)) + + +@pytest.fixture +def open_test_pikerd( + request: pytest.FixtureRequest, + tmp_path: Path, + tmpconfdir: Path, + loglevel: str, +): + + tmpconfdir_str: str = str(tmpconfdir) # NOTE: on linux the tmp config dir is generally located at: # /tmp/pytest-of-/pytest-/test_/ @@ -199,12 +228,6 @@ def open_test_pikerd( debug_mode=debug_mode, ) - # NOTE: the `tmp_dir` fixture will wipe any files older then 3 test - # sessions by default: - # https://docs.pytest.org/en/6.2.x/tmpdir.html#the-default-base-temporary-directory - # BUT, if we wanted to always wipe conf dir and all contained files, - # rmtree(str(tmp_path)) - # TODO: teardown checks such as, # - no leaked subprocs or shm buffers # - all requested container service are torn down diff --git a/tests/test_feeds.py b/tests/test_feeds.py index 371a6e89..07d368fa 100644 --- a/tests/test_feeds.py +++ b/tests/test_feeds.py @@ -7,8 +7,8 @@ from pprint import pprint from typing import AsyncContextManager import pytest -# import tractor import trio + from piker.data import ( ShmArray, open_feed, @@ -37,7 +37,7 @@ def test_multi_fqsn_feed( open_test_pikerd: AsyncContextManager, fqmes: set[str], loglevel: str, - ci_env: bool + ci_env: bool, ): ''' Start a real-time data feed for provided fqme and pull @@ -103,7 +103,6 @@ def test_multi_fqsn_feed( for fqme, quote in quotes.items(): cntr[fqme] += 1 - # await tractor.breakpoint() flume = feed.flumes[fqme] ohlcv: ShmArray = flume.rt_shm hist_ohlcv: ShmArray = flume.hist_shm