2015-09-12 01:57:22 +03:00
|
|
|
import os
|
2019-07-15 20:44:20 +03:00
|
|
|
from unittest import mock
|
2015-09-12 01:57:22 +03:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2018-05-16 06:40:27 +03:00
|
|
|
@pytest.fixture(autouse=True, scope='function')
|
2015-09-22 11:20:48 +03:00
|
|
|
def clean_environment():
|
2015-09-23 00:03:30 +03:00
|
|
|
"""Ensure all tests start with a clean environment.
|
2015-09-22 11:20:48 +03:00
|
|
|
|
2015-09-23 00:03:30 +03:00
|
|
|
Even if tests properly clean up after themselves, we still need this in
|
|
|
|
case the user runs tests with an already-polluted environment.
|
|
|
|
"""
|
|
|
|
with mock.patch.dict(
|
|
|
|
os.environ,
|
|
|
|
{'DUMB_INIT_DEBUG': '', 'DUMB_INIT_SETSID': ''},
|
|
|
|
):
|
|
|
|
yield
|
2015-09-22 11:20:48 +03:00
|
|
|
|
2015-09-23 00:03:30 +03:00
|
|
|
|
2018-05-16 06:40:27 +03:00
|
|
|
@pytest.fixture(params=['1', '0'])
|
2015-09-12 01:57:22 +03:00
|
|
|
def both_debug_modes(request):
|
2015-09-23 00:03:30 +03:00
|
|
|
with mock.patch.dict(os.environ, {'DUMB_INIT_DEBUG': request.param}):
|
|
|
|
yield
|
2015-09-12 01:57:22 +03:00
|
|
|
|
|
|
|
|
2018-05-16 06:40:27 +03:00
|
|
|
@pytest.fixture
|
2015-09-17 05:42:09 +03:00
|
|
|
def debug_disabled():
|
2015-09-23 00:03:30 +03:00
|
|
|
with mock.patch.dict(os.environ, {'DUMB_INIT_DEBUG': '0'}):
|
|
|
|
yield
|
2015-09-17 05:42:09 +03:00
|
|
|
|
|
|
|
|
2018-05-16 06:40:27 +03:00
|
|
|
@pytest.fixture(params=['1', '0'])
|
2015-09-12 01:57:22 +03:00
|
|
|
def both_setsid_modes(request):
|
2015-09-23 00:03:30 +03:00
|
|
|
with mock.patch.dict(os.environ, {'DUMB_INIT_SETSID': request.param}):
|
|
|
|
yield
|
2015-09-17 05:42:09 +03:00
|
|
|
|
|
|
|
|
2018-05-16 06:40:27 +03:00
|
|
|
@pytest.fixture
|
2015-09-17 05:42:09 +03:00
|
|
|
def setsid_enabled():
|
2015-09-23 00:03:30 +03:00
|
|
|
with mock.patch.dict(os.environ, {'DUMB_INIT_SETSID': '1'}):
|
|
|
|
yield
|
2015-09-17 05:42:09 +03:00
|
|
|
|
|
|
|
|
2018-05-16 06:40:27 +03:00
|
|
|
@pytest.fixture
|
2015-09-17 05:42:09 +03:00
|
|
|
def setsid_disabled():
|
2015-09-23 00:03:30 +03:00
|
|
|
with mock.patch.dict(os.environ, {'DUMB_INIT_SETSID': '0'}):
|
|
|
|
yield
|