add my.demo for testing out various approaches to configuring
This commit is contained in:
parent
d6f071e3b1
commit
0ac78143f2
4 changed files with 107 additions and 4 deletions
29
tests/demo.py
Normal file
29
tests/demo.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from pathlib import Path
|
||||
from more_itertools import ilen
|
||||
|
||||
# TODO NOTE: this wouldn't work because of an early my.config.demo import
|
||||
# from my.demo import items
|
||||
|
||||
def test_dynamic_config(tmp_path: Path) -> None:
|
||||
import my.config
|
||||
|
||||
class user_config:
|
||||
username = 'user'
|
||||
data_path = f'{tmp_path}/*.json'
|
||||
my.config.demo = user_config # type: ignore[misc, assignment]
|
||||
|
||||
from my.demo import items
|
||||
[item1, item2] = items()
|
||||
assert item1.username == 'user'
|
||||
|
||||
|
||||
import pytest # type: ignore
|
||||
@pytest.fixture(autouse=True)
|
||||
def prepare(tmp_path: Path):
|
||||
(tmp_path / 'data.json').write_text('''
|
||||
[
|
||||
{"key1": 1},
|
||||
{"key2": 2}
|
||||
]
|
||||
''')
|
||||
yield
|
Loading…
Add table
Add a link
Reference in a new issue