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.master
parent
588770d034
commit
c93d119873
|
@ -5,7 +5,6 @@ import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_trio
|
|
||||||
import tractor
|
import tractor
|
||||||
from piker import (
|
from piker import (
|
||||||
config,
|
config,
|
||||||
|
@ -149,19 +148,49 @@ async def _open_test_pikerd(
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def open_test_pikerd(
|
def tmpconfdir(
|
||||||
request: pytest.FixtureRequest,
|
|
||||||
tmp_path: Path,
|
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: Path = tmp_path / '_testing'
|
||||||
tmpconfdir.mkdir()
|
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
|
# override config dir in the root actor (aka
|
||||||
# this top level testing process).
|
# this top level testing process).
|
||||||
from piker import config
|
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:
|
# NOTE: on linux the tmp config dir is generally located at:
|
||||||
# /tmp/pytest-of-<username>/pytest-<run#>/test_<current_test_name>/
|
# /tmp/pytest-of-<username>/pytest-<run#>/test_<current_test_name>/
|
||||||
|
@ -199,12 +228,6 @@ def open_test_pikerd(
|
||||||
debug_mode=debug_mode,
|
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,
|
# TODO: teardown checks such as,
|
||||||
# - no leaked subprocs or shm buffers
|
# - no leaked subprocs or shm buffers
|
||||||
# - all requested container service are torn down
|
# - all requested container service are torn down
|
||||||
|
|
|
@ -7,8 +7,8 @@ from pprint import pprint
|
||||||
from typing import AsyncContextManager
|
from typing import AsyncContextManager
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
# import tractor
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from piker.data import (
|
from piker.data import (
|
||||||
ShmArray,
|
ShmArray,
|
||||||
open_feed,
|
open_feed,
|
||||||
|
@ -37,7 +37,7 @@ def test_multi_fqsn_feed(
|
||||||
open_test_pikerd: AsyncContextManager,
|
open_test_pikerd: AsyncContextManager,
|
||||||
fqmes: set[str],
|
fqmes: set[str],
|
||||||
loglevel: str,
|
loglevel: str,
|
||||||
ci_env: bool
|
ci_env: bool,
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Start a real-time data feed for provided fqme and pull
|
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():
|
for fqme, quote in quotes.items():
|
||||||
cntr[fqme] += 1
|
cntr[fqme] += 1
|
||||||
|
|
||||||
# await tractor.breakpoint()
|
|
||||||
flume = feed.flumes[fqme]
|
flume = feed.flumes[fqme]
|
||||||
ohlcv: ShmArray = flume.rt_shm
|
ohlcv: ShmArray = flume.rt_shm
|
||||||
hist_ohlcv: ShmArray = flume.hist_shm
|
hist_ohlcv: ShmArray = flume.hist_shm
|
||||||
|
|
Loading…
Reference in New Issue