diff --git a/Makefile b/Makefile index f473784..a535518 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,9 @@ DOCKER_DEB_TEST := sh -euxc ' \ && tmp=$$(mktemp -d) \ && cp -r /mnt/* "$$tmp" \ && cd "$$tmp" \ - && pip install pytest \ + && pip install --upgrade pip \ + && /usr/local/bin/pip install --upgrade setuptools distribute \ + && /usr/local/bin/pip install -r requirements-dev.txt \ && py.test tests/ \ && exec dumb-init /mnt/tests/test-zombies \ ' @@ -26,8 +28,10 @@ DOCKER_PYTHON_TEST := sh -uexc ' \ && cd "$$tmp" \ && python setup.py clean \ && python setup.py sdist \ - && pip install -vv dist/*.tar.gz \ - && pip install pytest \ + && pip install --upgrade pip \ + && /usr/local/bin/pip install --upgrade setuptools distribute \ + && /usr/local/bin/pip install -vv dist/*.tar.gz \ + && /usr/local/bin/pip install -r requirements-dev.txt \ && py.test tests/ \ && exec dumb-init /mnt/tests/test-zombies \ ' diff --git a/debian/control b/debian/control index 55d74d4..17fa77e 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,8 @@ Section: utils Priority: extra Maintainer: Chris Kuehl Uploaders: Kent Wills -Build-Depends: debhelper (>= 7), gcc, fakeroot, python, python-pytest +Build-Depends: debhelper (>= 7), gcc, fakeroot, python, python-pytest, + python-mock Standards-Version: 3.9.6 Package: dumb-init diff --git a/requirements-dev.txt b/requirements-dev.txt index 2dac807..6e596f7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ +mock pre-commit>=0.5.0 pytest pytest-timeout diff --git a/tests/conftest.py b/tests/conftest.py index 86b8c2a..2f10460 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,35 +1,48 @@ import os +import mock import pytest -@pytest.fixture(autouse=True, scope='function') +@pytest.yield_fixture(autouse=True, scope='function') def clean_environment(): - """Ensure tests don't pollute each others' environment variables.""" - os.environ.pop('DUMB_INIT_DEBUG', None) - os.environ.pop('DUMB_INIT_SETSID', None) + """Ensure all tests start with a clean environment. + + 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 -@pytest.fixture(params=['1', '0']) +@pytest.yield_fixture(params=['1', '0']) def both_debug_modes(request): - os.environ['DUMB_INIT_DEBUG'] = request.param + with mock.patch.dict(os.environ, {'DUMB_INIT_DEBUG': request.param}): + yield -@pytest.fixture +@pytest.yield_fixture def debug_disabled(): - os.environ['DUMB_INIT_DEBUG'] = '0' + with mock.patch.dict(os.environ, {'DUMB_INIT_DEBUG': '0'}): + yield -@pytest.fixture(params=['1', '0']) +@pytest.yield_fixture(params=['1', '0']) def both_setsid_modes(request): - os.environ['DUMB_INIT_SETSID'] = request.param + with mock.patch.dict(os.environ, {'DUMB_INIT_SETSID': request.param}): + yield -@pytest.fixture +@pytest.yield_fixture def setsid_enabled(): - os.environ['DUMB_INIT_SETSID'] = '1' + with mock.patch.dict(os.environ, {'DUMB_INIT_SETSID': '1'}): + yield -@pytest.fixture +@pytest.yield_fixture def setsid_disabled(): - os.environ['DUMB_INIT_SETSID'] = '0' + with mock.patch.dict(os.environ, {'DUMB_INIT_SETSID': '0'}): + yield