is there way run .py @ beginning besides __init__.py
?
my problem need save current database state before parsing of files changes things. because have temporary tests variables change, if can store state before parsing fixed since can restore @ end of session.
i need run .py not before actual test session starts before other files parsed.
example:
console> py.test tests/test_example.py
- need run here
collecting 0 items
tests/test_example.py
==== test session starts ====
conftest.py
runs here
you __init__.py
solution when there __init__.py
in testing directory, pytest runs module. (instead of running py._path.pyimport
, runs __init__.py
) breaks tests , imports throughout whole tests/ directory
so maybe can crate own py._path.pyimport
, doesn't seem safest/correct way. or possible call __init__.py
, still run py._path.pyimport
after?
you use pytest's plugin hooks conftest.py
so.
i'm not sure hook best case. pytest_configure
.
for example, in conftest.py
:
def pytest_configure(): print("hello world")
you get:
$ py.test hello world! =================== test session starts ==================== platform linux -- python 3.5.1, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 [..] collecting 120 items