WIP: initial repro for #8412
This commit is contained in:
parent
620e819656
commit
d488f899d8
|
@ -0,0 +1,45 @@
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class EnvironmentAwareMixin:
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _monkeypatch(self, monkeypatch):
|
||||||
|
self._envpatcher = monkeypatch
|
||||||
|
|
||||||
|
def set_environ(self, name, value):
|
||||||
|
self._envpatcher.setenv(name, value)
|
||||||
|
|
||||||
|
|
||||||
|
# This arrangement fails: setup_method runs before _monkeypatch
|
||||||
|
class MyPytestBase(
|
||||||
|
EnvironmentAwareMixin,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestSomething(MyPytestBase):
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def setup_method(self):
|
||||||
|
self.set_environ("X", "1")
|
||||||
|
|
||||||
|
def test_something(self):
|
||||||
|
assert os.environ["X"] == "1"
|
||||||
|
|
||||||
|
|
||||||
|
# This arrangement works: _monkeypatch runs before setUp
|
||||||
|
class MyUnittestBase(
|
||||||
|
EnvironmentAwareMixin,
|
||||||
|
unittest.TestCase,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestSomethingElse(MyUnittestBase):
|
||||||
|
def setUp(self):
|
||||||
|
self.set_environ("X", "1")
|
||||||
|
|
||||||
|
def test_something_else(self):
|
||||||
|
assert os.environ["X"] == "1"
|
|
@ -0,0 +1,7 @@
|
||||||
|
from _pytest.pytester import Pytester
|
||||||
|
|
||||||
|
|
||||||
|
def test_order(pytester: Pytester) -> None:
|
||||||
|
pytester.copy_example("order_issue.py")
|
||||||
|
rep = pytester.runpytest("order_issue.py")
|
||||||
|
rep.assert_outcomes(passed=2)
|
Loading…
Reference in New Issue