Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fake_subTest() missing 1 required positional argument: 'self' #2462

Closed
jimmy-lt opened this issue Jun 12, 2020 · 2 comments · Fixed by #2513
Closed

fake_subTest() missing 1 required positional argument: 'self' #2462

jimmy-lt opened this issue Jun 12, 2020 · 2 comments · Fixed by #2513
Labels
bug something is clearly wrong here

Comments

@jimmy-lt
Copy link

Hypotesis is failing when running a unittest with a subTest().

Traceback (most recent call last):
  File "/tests/common/test_components.py", line 91, in test__located_component_multiple_components_registration
    c1_name=registry_identifier_strategy(),
  File "/lib/python3.8/site-packages/hypothesis/core.py", line 1102, in wrapped_test
    raise the_error_hypothesis_found
  File "/tests/common/test_components.py", line 150, in test__located_component_multiple_components_registration
    with self.subTest(action='count'):
  File "/usr/lib/python3.8/contextlib.py", line 240, in helper
    return _GeneratorContextManager(func, args, kwds)
  File "/usr/lib/python3.8/contextlib.py", line 83, in __init__
    self.gen = func(*args, **kwds)
TypeError: fake_subTest() missing 1 required positional argument: 'self'

Version information

  • Python 3.8.3
  • hypothesis 5.16.1
@Zac-HD
Copy link
Member

Zac-HD commented Jun 12, 2020

Please share a complete example that I can run to reproduce this problem.

@jimmy-lt
Copy link
Author

jimmy-lt commented Jun 12, 2020

With subTest()

import unittest
from hypothesis import given, strategies as st


class MyTest(unittest.TestCase):
    @given(s=st.text())
    def test_subtest(self, s):
        with self.subTest(text=s):
            self.assertIs(type(s), str)
$ python3 -m unittest tests.MyTest
Falsifying example: test_subtest(
    self=<tests.MyTest testMethod=test_subtest>, s='',
)
E
======================================================================
ERROR: test_subtest (tests.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tests.py", line 7, in test_subtest
    def test_subtest(self, s):
  File "/usr/lib/python3.8/site-packages/hypothesis/core.py", line 1102, in wrapped_test
    raise the_error_hypothesis_found
  File "/tests.py", line 8, in test_subtest
    with self.subTest(text=s):
  File "/usr/lib/python3.8/contextlib.py", line 240, in helper
    return _GeneratorContextManager(func, args, kwds)
  File "/usr/lib/python3.8/contextlib.py", line 83, in __init__
    self.gen = func(*args, **kwds)
TypeError: fake_subTest() missing 1 required positional argument: 'self'

----------------------------------------------------------------------
Ran 1 test in 0.209s

FAILED (errors=1)

Without subTest()

import unittest
from hypothesis import given, strategies as st


class MyTest(unittest.TestCase):
    @given(s=st.text())
    def test_subtest(self, s):
        self.assertIs(type(s), str)
$ python3 -m unittest -v tests.MyTest
test_subtest (tests.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.102s

OK

@Zac-HD Zac-HD added the bug something is clearly wrong here label Jun 12, 2020
fruch added a commit to fruch/hypothesis that referenced this issue Jul 26, 2020
fruch added a commit to fruch/hypothesis that referenced this issue Jul 26, 2020
fruch added a commit to fruch/hypothesis that referenced this issue Jul 26, 2020
fruch added a commit to fruch/hypothesis that referenced this issue Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants