Skip to content

Commit 95e2480

Browse files
committed
Allow a registered helper to behave as a regular function.
Fixes #4
1 parent 3ba5228 commit 95e2480

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pytest_helpers_namespace/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def register(self, func):
6464
)
6565
)
6666
self._registry[func.__name__] = wraps(func)(FuncWrapper(func))
67-
return self
67+
return func
6868

6969
def __getattribute__(self, name):
7070
if name in ('__class__', '_registry', 'register'):

tests/test_helpers_namespace.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,28 @@ def test_helpers():
191191

192192
# make sure that that we get a '0' exit code for the testsuite
193193
assert result.ret != 0
194+
195+
196+
def test_helper_as_regular_function(testdir):
197+
testdir.makepyfile('''
198+
import pytest
199+
200+
@pytest.helpers.register
201+
def foo():
202+
return 'bar'
203+
204+
def test_helpers():
205+
assert pytest.helpers.foo() == 'bar'
206+
assert foo() == 'bar'
207+
print('PASSED')
208+
''')
209+
210+
result = testdir.runpytest('-s')
211+
212+
# fnmatch_lines does an assertion internally
213+
result.stdout.fnmatch_lines([
214+
'test_helper_as_regular_function.py PASSED',
215+
])
216+
217+
# make sure that that we get a '0' exit code for the testsuite
218+
assert result.ret == 0

0 commit comments

Comments
 (0)