Skip to content

Commit df46afc

Browse files
committed
Change fixture argument handling tests to unit-tests
1 parent 6918d07 commit df46afc

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

testing/python/fixtures.py

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,54 +4108,34 @@ def test_fixture_named_request(testdir):
41084108

41094109
def test_fixture_duplicated_arguments(testdir):
41104110
"""Raise error if there are positional and keyword arguments for the same parameter (#1682)."""
4111-
testdir.makepyfile(
4112-
"""
4113-
import pytest
4111+
with pytest.raises(TypeError) as excinfo:
41144112

4115-
with pytest.raises(TypeError) as excinfo:
4116-
4117-
@pytest.fixture("session", scope="session")
4118-
def arg(arg):
4119-
pass
4120-
4121-
def test_error():
4122-
assert (
4123-
str(excinfo.value)
4124-
== "The fixture arguments are defined as positional and keyword: scope. "
4125-
"Use only keyword arguments."
4126-
)
4113+
@pytest.fixture("session", scope="session")
4114+
def arg(arg):
4115+
pass
41274116

4128-
"""
4117+
assert (
4118+
str(excinfo.value)
4119+
== "The fixture arguments are defined as positional and keyword: scope. "
4120+
"Use only keyword arguments."
41294121
)
41304122

4131-
reprec = testdir.inline_run()
4132-
reprec.assertoutcome(passed=1)
4133-
41344123

41354124
def test_fixture_with_positionals(testdir):
41364125
"""Raise warning, but the positionals should still works (#1682)."""
4137-
testdir.makepyfile(
4138-
"""
4139-
import os
4126+
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS
41404127

4141-
import pytest
4142-
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS
4128+
with pytest.warns(pytest.PytestDeprecationWarning) as warnings:
41434129

4144-
with pytest.warns(pytest.PytestDeprecationWarning) as warnings:
4145-
@pytest.fixture("function", [0], True)
4146-
def arg(monkeypatch):
4147-
monkeypatch.setenv("AUTOUSE_WORKS", "1")
4130+
@pytest.fixture("function", [0], True)
4131+
def arg(monkeypatch):
4132+
monkeypatch.setenv("AUTOUSE_WORKS", "1")
41484133

4134+
assert str(warnings[0].message) == str(FIXTURE_POSITIONAL_ARGUMENTS)
41494135

4150-
def test_autouse():
4151-
assert os.environ.get("AUTOUSE_WORKS") == "1"
4152-
assert str(warnings[0].message) == str(FIXTURE_POSITIONAL_ARGUMENTS)
4153-
4154-
"""
4155-
)
4156-
4157-
reprec = testdir.inline_run()
4158-
reprec.assertoutcome(passed=1)
4136+
assert arg._pytestfixturefunction.scope == "function"
4137+
assert arg._pytestfixturefunction.params == (0,)
4138+
assert arg._pytestfixturefunction.autouse
41594139

41604140

41614141
def test_indirect_fixture_does_not_break_scope(testdir):

0 commit comments

Comments
 (0)