MCPcopy
hub / github.com/benoitc/gunicorn / check_environ

Function check_environ

tests/test_systemd.py:15–40  ·  view source on GitHub ↗

A context manager that asserts post-conditions of ``listen_fds`` at exit. This helper is used to ease checking of the test post-conditions for the systemd socket activation tests that parametrize the call argument.

(unset=True)

Source from the content-addressed store, hash-verified

13
14@contextmanager
15def check_environ(unset=True):
16 """
17 A context manager that asserts post-conditions of ``listen_fds`` at exit.
18
19 This helper is used to ease checking of the test post-conditions for the
20 systemd socket activation tests that parametrize the call argument.
21 """
22
23 with mock.patch.dict(os.environ):
24 old_fds = os.environ.get('LISTEN_FDS', None)
25 old_pid = os.environ.get('LISTEN_PID', None)
26
27 yield
28
29 if unset:
30 assert 'LISTEN_FDS' not in os.environ, \
31 "LISTEN_FDS should have been unset"
32 assert 'LISTEN_PID' not in os.environ, \
33 "LISTEN_PID should have been unset"
34 else:
35 new_fds = os.environ.get('LISTEN_FDS', None)
36 new_pid = os.environ.get('LISTEN_PID', None)
37 assert new_fds == old_fds, \
38 "LISTEN_FDS should not have been changed"
39 assert new_pid == old_pid, \
40 "LISTEN_PID should not have been changed"
41
42
43@pytest.mark.parametrize("unset", [True, False])

Calls 1

getMethod · 0.45

Tested by

no test coverage detected