Merge branch 'pytest-dev'

# Conflicts:
#	AUTHORS
This commit is contained in:
elizabeth
2015-08-24 22:55:11 +03:00
149 changed files with 1334 additions and 427 deletions

View File

@@ -1,6 +1,8 @@
import sys
from textwrap import dedent
import pytest, py
from _pytest.main import EXIT_NOTESTSCOLLECTED
class TestModule:
def test_failing_import(self, testdir):
@@ -412,9 +414,19 @@ class TestFunction:
['overridden'])
def test_overridden_via_param(value):
assert value == 'overridden'
@pytest.mark.parametrize('somevalue', ['overridden'])
def test_not_overridden(value, somevalue):
assert value == 'value'
assert somevalue == 'overridden'
@pytest.mark.parametrize('other,value', [('foo', 'overridden')])
def test_overridden_via_multiparam(other, value):
assert other == 'foo'
assert value == 'overridden'
""")
rec = testdir.inline_run()
rec.assertoutcome(passed=1)
rec.assertoutcome(passed=3)
def test_parametrize_overrides_parametrized_fixture(self, testdir):
@@ -472,6 +484,38 @@ class TestFunction:
config.pluginmanager.register(MyPlugin2())
config.hook.pytest_pyfunc_call(pyfuncitem=item)
def test_multiple_parametrize(self, testdir):
modcol = testdir.getmodulecol("""
import pytest
@pytest.mark.parametrize('x', [0, 1])
@pytest.mark.parametrize('y', [2, 3])
def test1(x, y):
pass
""")
colitems = modcol.collect()
assert colitems[0].name == 'test1[2-0]'
assert colitems[1].name == 'test1[2-1]'
assert colitems[2].name == 'test1[3-0]'
assert colitems[3].name == 'test1[3-1]'
def test_issue751_multiple_parametrize_with_ids(self, testdir):
modcol = testdir.getmodulecol("""
import pytest
@pytest.mark.parametrize('x', [0], ids=['c'])
@pytest.mark.parametrize('y', [0, 1], ids=['a', 'b'])
class Test(object):
def test1(self, x, y):
pass
def test2(self, x, y):
pass
""")
colitems = modcol.collect()[0].collect()[0].collect()
assert colitems[0].name == 'test1[a-c]'
assert colitems[1].name == 'test1[b-c]'
assert colitems[2].name == 'test2[a-c]'
assert colitems[3].name == 'test2[b-c]'
class TestSorting:
def test_check_equality(self, testdir):
modcol = testdir.getmodulecol("""
@@ -864,7 +908,7 @@ def test_unorderable_types(testdir):
""")
result = testdir.runpytest()
assert "TypeError" not in result.stdout.str()
assert result.ret == 0
assert result.ret == EXIT_NOTESTSCOLLECTED
def test_collect_functools_partial(testdir):

View File

@@ -1598,6 +1598,22 @@ class TestFixtureMarker:
reprec = testdir.inline_run()
reprec.assertoutcome(passed=4)
def test_multiple_parametrization_issue_736(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1,2,3])
def foo(request):
return request.param
@pytest.mark.parametrize('foobar', [4,5,6])
def test_issue(foo, foobar):
assert foo in [1,2,3]
assert foobar in [4,5,6]
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=9)
def test_scope_session(self, testdir):
testdir.makepyfile("""
import pytest

View File

@@ -1,3 +1,4 @@
import re
import pytest, py
from _pytest import python as funcargs
@@ -138,6 +139,8 @@ class TestMetafunc:
("three", "three hundred"),
(True, False),
(None, None),
(re.compile('foo'), re.compile('bar')),
(str, int),
(list("six"), [66, 66]),
(set([7]), set("seven")),
(tuple("eight"), (8, -8, 8))
@@ -147,9 +150,18 @@ class TestMetafunc:
"three-three hundred",
"True-False",
"None-None",
"a5-b5",
"a6-b6",
"a7-b7"]
"foo-bar",
"str-int",
"a7-b7",
"a8-b8",
"a9-b9"]
def test_idmaker_enum(self):
from _pytest.python import idmaker
enum = pytest.importorskip("enum")
e = enum.Enum("Foo", "one, two")
result = idmaker(("a", "b"), [(e.one, e.two)])
assert result == ["Foo.one-Foo.two"]
@pytest.mark.issue351
def test_idmaker_idfn(self):
@@ -742,18 +754,20 @@ class TestMetafuncFunctional:
reprec.assert_outcomes(passed=4)
@pytest.mark.issue463
def test_parameterize_misspelling(self, testdir):
@pytest.mark.parametrize('attr', ['parametrise', 'parameterize',
'parameterise'])
def test_parametrize_misspelling(self, testdir, attr):
testdir.makepyfile("""
import pytest
@pytest.mark.parameterize("x", range(2))
@pytest.mark.{0}("x", range(2))
def test_foo(x):
pass
""")
""".format(attr))
reprec = testdir.inline_run('--collectonly')
failures = reprec.getfailures()
assert len(failures) == 1
expectederror = "MarkerError: test_foo has 'parameterize', spelling should be 'parametrize'"
expectederror = "MarkerError: test_foo has '{0}', spelling should be 'parametrize'".format(attr)
assert expectederror in failures[0].longrepr.reprcrash.message

View File

@@ -34,7 +34,6 @@ class TestRaises:
raise BuiltinAssertionError
""")
@pytest.mark.skipif('sys.version < "2.5"')
def test_raises_as_contextmanager(self, testdir):
testdir.makepyfile("""
from __future__ import with_statement