From df46afc96d05823f6f13354b58cdba81dcf66336 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 18 Sep 2019 07:47:41 -0300 Subject: [PATCH] Change fixture argument handling tests to unit-tests --- testing/python/fixtures.py | 54 ++++++++++++-------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 2a0c0341a..5b1459fb6 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -4108,54 +4108,34 @@ def test_fixture_named_request(testdir): def test_fixture_duplicated_arguments(testdir): """Raise error if there are positional and keyword arguments for the same parameter (#1682).""" - testdir.makepyfile( - """ - import pytest + with pytest.raises(TypeError) as excinfo: - with pytest.raises(TypeError) as excinfo: + @pytest.fixture("session", scope="session") + def arg(arg): + pass - @pytest.fixture("session", scope="session") - def arg(arg): - pass - - def test_error(): - assert ( - str(excinfo.value) - == "The fixture arguments are defined as positional and keyword: scope. " - "Use only keyword arguments." - ) - - """ + assert ( + str(excinfo.value) + == "The fixture arguments are defined as positional and keyword: scope. " + "Use only keyword arguments." ) - reprec = testdir.inline_run() - reprec.assertoutcome(passed=1) - def test_fixture_with_positionals(testdir): """Raise warning, but the positionals should still works (#1682).""" - testdir.makepyfile( - """ - import os + from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS - import pytest - from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS + with pytest.warns(pytest.PytestDeprecationWarning) as warnings: - with pytest.warns(pytest.PytestDeprecationWarning) as warnings: - @pytest.fixture("function", [0], True) - def arg(monkeypatch): - monkeypatch.setenv("AUTOUSE_WORKS", "1") + @pytest.fixture("function", [0], True) + def arg(monkeypatch): + monkeypatch.setenv("AUTOUSE_WORKS", "1") + assert str(warnings[0].message) == str(FIXTURE_POSITIONAL_ARGUMENTS) - def test_autouse(): - assert os.environ.get("AUTOUSE_WORKS") == "1" - assert str(warnings[0].message) == str(FIXTURE_POSITIONAL_ARGUMENTS) - - """ - ) - - reprec = testdir.inline_run() - reprec.assertoutcome(passed=1) + assert arg._pytestfixturefunction.scope == "function" + assert arg._pytestfixturefunction.params == (0,) + assert arg._pytestfixturefunction.autouse def test_indirect_fixture_does_not_break_scope(testdir):