From dbf94f6f17f13e32e8de9bfb041f16142331d9b1 Mon Sep 17 00:00:00 2001 From: Milosz Sliwinski Date: Sat, 8 Dec 2018 12:36:29 +0100 Subject: [PATCH] Fixes #276: Patch testdir fixture to run config tests in subprocess to not mess with pytest internal state --- tests/conftest.py | 1 + tests/testdir_patch.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/testdir_patch.py diff --git a/tests/conftest.py b/tests/conftest.py index 8f90a78a9..f1a09f0d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ """Configuration for pytest runner.""" from pytest_bdd import given, when +from tests.testdir_patch import testdir pytest_plugins = "pytester" diff --git a/tests/testdir_patch.py b/tests/testdir_patch.py new file mode 100644 index 000000000..1939ab3a5 --- /dev/null +++ b/tests/testdir_patch.py @@ -0,0 +1,20 @@ +"""Tests that are testing config values need to be run using subprocess +to guarantee test separation and avoid messing with pytest internal state. +Pytest bug: https://github.com/pytest-dev/pytest/issues/4495 + +TODO: Remove this patch once above bug is fixed +""" +import pytest +from _pytest.pytester import Testdir + + +class PatchedTestdir(Testdir): + + def makeini(self, source): + self._runpytest_method = self.runpytest_subprocess + return self.makefile(".ini", tox=source) + + +@pytest.fixture +def testdir(request, tmpdir_factory): + return PatchedTestdir(request, tmpdir_factory)