summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2017-09-06 08:24:00 +0200
committerGitHub <noreply@github.com>2017-09-06 08:24:00 +0200
commitad36407747da6b6efa85fa202031f9f2e45741e3 (patch)
treec5011de7faff6a63a39282d1dc50af1a61e2f6d2 /testing
parent181bd60bf99021e3d8936ade5f92d408c53d3419 (diff)
parent1fc185b6405e63df37eb16bbbc62c0ed50d84f21 (diff)
downloadpytest-ad36407747da6b6efa85fa202031f9f2e45741e3.tar.gz
Merge pull request #2700 from nicoddemus/staticmethods-fixtures
Allow tests declared as @staticmethod to use fixtures
Diffstat (limited to 'testing')
-rw-r--r--testing/python/collect.py14
-rw-r--r--testing/python/fixture.py6
2 files changed, 18 insertions, 2 deletions
diff --git a/testing/python/collect.py b/testing/python/collect.py
index bd7013b44..b24c0b2fd 100644
--- a/testing/python/collect.py
+++ b/testing/python/collect.py
@@ -147,11 +147,21 @@ class TestClass(object):
])
def test_static_method(self, testdir):
+ """Support for collecting staticmethod tests (#2528, #2699)"""
testdir.getmodulecol("""
+ import pytest
class Test(object):
@staticmethod
def test_something():
pass
+
+ @pytest.fixture
+ def fix(self):
+ return 1
+
+ @staticmethod
+ def test_fix(fix):
+ assert fix == 1
""")
result = testdir.runpytest()
if sys.version_info < (2, 7):
@@ -162,8 +172,8 @@ class TestClass(object):
])
else:
result.stdout.fnmatch_lines([
- "*collected 1 item*",
- "*1 passed in*",
+ "*collected 2 items*",
+ "*2 passed in*",
])
def test_setup_teardown_class_as_classmethod(self, testdir):
diff --git a/testing/python/fixture.py b/testing/python/fixture.py
index f8aef802f..06b08d68e 100644
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -29,10 +29,16 @@ def test_getfuncargnames():
def f(self, arg1, arg2="hello"):
pass
+ @staticmethod
+ def static(arg1, arg2):
+ pass
+
assert fixtures.getfuncargnames(A().f) == ('arg1',)
if sys.version_info < (3, 0):
assert fixtures.getfuncargnames(A.f) == ('arg1',)
+ assert fixtures.getfuncargnames(A.static, cls=A) == ('arg1', 'arg2')
+
class TestFillFixtures(object):
def test_fillfuncargs_exposed(self):