MCPcopy Create free account
hub / github.com/pytest-dev/pytest / SetupState

Class SetupState

src/_pytest/runner.py:406–538  ·  view source on GitHub ↗

Shared state for setting up/tearing down test items or collectors in a session. Suppose we have a collection tree as follows: The SetupState maintains a stack. T

Source from the content-addressed store, hash-verified

404
405
406class SetupState:
407 """Shared state for setting up/tearing down test items or collectors
408 in a session.
409
410 Suppose we have a collection tree as follows:
411
412 <Session session>
413 <Module mod1>
414 <Function item1>
415 <Module mod2>
416 <Function item2>
417
418 The SetupState maintains a stack. The stack starts out empty:
419
420 []
421
422 During the setup phase of item1, setup(item1) is called. What it does
423 is:
424
425 push session to stack, run session.setup()
426 push mod1 to stack, run mod1.setup()
427 push item1 to stack, run item1.setup()
428
429 The stack is:
430
431 [session, mod1, item1]
432
433 While the stack is in this shape, it is allowed to add finalizers to
434 each of session, mod1, item1 using addfinalizer().
435
436 During the teardown phase of item1, teardown_exact(item2) is called,
437 where item2 is the next item to item1. What it does is:
438
439 pop item1 from stack, run its teardowns
440 pop mod1 from stack, run its teardowns
441
442 mod1 was popped because it ended its purpose with item1. The stack is:
443
444 [session]
445
446 During the setup phase of item2, setup(item2) is called. What it does
447 is:
448
449 push mod2 to stack, run mod2.setup()
450 push item2 to stack, run item2.setup()
451
452 Stack:
453
454 [session, mod2, item2]
455
456 During the teardown phase of item2, teardown_exact(None) is called,
457 because item2 is the last item. What it does is:
458
459 pop item2 from stack, run its teardowns
460 pop mod2 from stack, run its teardowns
461 pop session from stack, run its teardowns
462
463 Stack:

Callers 1

pytest_sessionstartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected