Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest: are pytest_sessionstart() and pytest_sessionfinish() valid hooks?

Tags:

pytest

are pytest_sessionstart(session) and pytest_sessionfinish(session) valid hooks? They are not described in dev hook docs or latest hook docs

What is the difference between them and pytest_configure(config)/pytest_unconfigure(config)?

In docs it is said:

pytest_configure(config)called after command line options have been parsed. and all plugins and initial conftest files been loaded.

and

pytest_unconfigure(config) called before test process is exited.

Session is the same, right?

Thanks!

like image 812
Alex Okrushko Avatar asked Sep 25 '12 15:09

Alex Okrushko


1 Answers

The bad news is that the situation with sessionstart/configure is not very well specified. Sessionstart in particular is not much documented because the semantics differ if one is in the xdist/distribution case or not. One can distinguish these situations but it's all a bit too complicated.

The good news is that pytest-2.3 should make things easier. If you define a @fixture with scope="session" you can implement a fixture that is called once per process within which test execute.
For distributed testing, this means once per test slave. For single-process testing, it means once for the whole test run. In either case, if you do a "--collectonly" run, or "-h" or other options that do not involve the running of tests, then fixture functions will not execute at all.

Hope this clarifies.

like image 124
hpk42 Avatar answered Sep 26 '22 19:09

hpk42