Merge pull request #7948 from bluetech/testing-conftest-pytester
testing: make conftest stuff check for pytester not testdir
This commit is contained in:
commit
20b710c4b4
|
@ -3,7 +3,8 @@ import sys
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.pytester import Testdir
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
|
from _pytest.pytester import Pytester
|
||||||
|
|
||||||
if sys.gettrace():
|
if sys.gettrace():
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ def pytest_collection_modifyitems(items):
|
||||||
# (https://github.com/pytest-dev/pytest/issues/5070)
|
# (https://github.com/pytest-dev/pytest/issues/5070)
|
||||||
neutral_items.append(item)
|
neutral_items.append(item)
|
||||||
else:
|
else:
|
||||||
if "testdir" in fixtures:
|
if "pytester" in fixtures:
|
||||||
co_names = item.function.__code__.co_names
|
co_names = item.function.__code__.co_names
|
||||||
if spawn_names.intersection(co_names):
|
if spawn_names.intersection(co_names):
|
||||||
item.add_marker(pytest.mark.uses_pexpect)
|
item.add_marker(pytest.mark.uses_pexpect)
|
||||||
|
@ -103,13 +104,13 @@ def tw_mock():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dummy_yaml_custom_test(testdir):
|
def dummy_yaml_custom_test(pytester: Pytester):
|
||||||
"""Writes a conftest file that collects and executes a dummy yaml test.
|
"""Writes a conftest file that collects and executes a dummy yaml test.
|
||||||
|
|
||||||
Taken from the docs, but stripped down to the bare minimum, useful for
|
Taken from the docs, but stripped down to the bare minimum, useful for
|
||||||
tests which needs custom items collected.
|
tests which needs custom items collected.
|
||||||
"""
|
"""
|
||||||
testdir.makeconftest(
|
pytester.makeconftest(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -126,13 +127,13 @@ def dummy_yaml_custom_test(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
testdir.makefile(".yaml", test1="")
|
pytester.makefile(".yaml", test1="")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def testdir(testdir: Testdir) -> Testdir:
|
def pytester(pytester: Pytester, monkeypatch: MonkeyPatch) -> Pytester:
|
||||||
testdir.monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
|
monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
|
||||||
return testdir
|
return pytester
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
|
@ -178,7 +179,7 @@ def color_mapping():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_timing(monkeypatch):
|
def mock_timing(monkeypatch: MonkeyPatch):
|
||||||
"""Mocks _pytest.timing with a known object that can be used to control timing in tests
|
"""Mocks _pytest.timing with a known object that can be used to control timing in tests
|
||||||
deterministically.
|
deterministically.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue