Pytest: pytest_sessionstart () and pytest_sessionfinish () are valid interceptors?

are pytest_sessionstart(session) and pytest_sessionfinish(session) valid interceptors? They are not described in dev hook docs or recent entries.

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

The docs say:

pytest_configure(config) called after the command line parameters have been parsed. and all plugins and loaded source files for answers.

and

pytest_unconfigure(config) , called before the test process completes.

The session is the same, right?

Thanks!

+4
source share
1 answer

The bad news is that the situation with sessionstart / configure is not well indicated. Sessionstart, in particular, is not well documented, because the semantics are different if it is in the case of xdist / distribution or not. You can distinguish between these situations, but all this is too complicated.

The good news is that pytest-2.3 should ease the situation. If you define the @setup function (soon to be renamed to @fixture) with scope = "session", you can implement a tool that is called once for each process in which the test is running. For distributed testing, this means once for each slave. For uniprocessor testing, this means once for the entire test run. In any case, if you execute "-collectonly" or "-h" or other parameters that are not related to running the tests, then the binding functions are not performed at all.

Hope this clarifies.

+5
source

Source: https://habr.com/ru/post/1436188/


All Articles