Yelp / Testify

A more pythonic testing framework.
Other
308 stars 67 forks source link

Creating a class variable named bucket conficts with MetaTestCase.bucket #206

Closed att14 closed 10 years ago

att14 commented 10 years ago
import testify as T

class BucketTest(T.TestCase):

    @T.let
    def bucket(self):
        return 'foobar'

    def test_bucket(self):
        assert True == True
atribone@140-sfoeng49-85:~/code$ testify --bucket=1 bucket_test
Traceback (most recent call last):
  File "/usr/local/bin/testify", line 5, in <module>
    pkg_resources.run_script('testify==0.4.0', 'testify')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 489, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1207, in run_script
    execfile(script_filename, namespace, namespace)
  File "/Library/Python/2.7/site-packages/testify-0.4.0-py2.7.egg/EGG-INFO/scripts/testify", line 25, in <module>
    test_program.TestProgram()
  File "/Library/Python/2.7/site-packages/testify-0.4.0-py2.7.egg/testify/test_program.py", line 222, in __init__
    self.run()
  File "/Library/Python/2.7/site-packages/testify-0.4.0-py2.7.egg/testify/test_program.py", line 299, in run
    result = runner.run()
  File "/Library/Python/2.7/site-packages/testify-0.4.0-py2.7.egg/testify/test_runner.py", line 128, in run
    for test_case in self.discover():
  File "/Library/Python/2.7/site-packages/testify-0.4.0-py2.7.egg/testify/test_runner.py", line 103, in discover
    discovered_tests = list(discover_inner())
  File "/Library/Python/2.7/site-packages/testify-0.4.0-py2.7.egg/testify/test_runner.py", line 88, in discover_inner
    or (override_bucket is None and test_case_class.bucket(self.bucket_count, self.bucket_salt) == self.bucket)
TypeError: 'let' object is not callable

The name should be changed to something like testify_bucket or bucket_.

mrtyler commented 10 years ago

I renamed it to _testify_bucket and ran your example code and got a different error:

[tyler@toaster:~/Testify]$ PYTHONPATH=~/Testify ~/Testify/bin/testify -v tmp2.py --bucket=1
HERE
Traceback (most recent call last):
  File "/Users/tyler/Testify/bin/testify", line 25, in <module>
    test_program.TestProgram()
  File "/Users/tyler/Testify/testify/test_program.py", line 222, in __init__
    self.run()
  File "/Users/tyler/Testify/testify/test_program.py", line 299, in run
    result = runner.run()
  File "/Users/tyler/Testify/testify/test_runner.py", line 133, in run
    for test_case in self.discover():
  File "/Users/tyler/Testify/testify/test_runner.py", line 108, in discover
    discovered_tests = list(discover_inner())
  File "/Users/tyler/Testify/testify/test_runner.py", line 93, in discover_inner
    or (override_bucket is None and test_case_class._testify_bucket(self.bucket_count, self.bucket_salt) == self.bucket)
  File "/Users/tyler/Testify/testify/test_case.py", line 81, in _testify_bucket
    return hash(MetaTestCase._cmp_str(cls)) % bucket_count
TypeError: unsupported operand type(s) for %: 'int' and 'NoneType'

But this appears to be an unrelated error, which I have filed as #209.

Since, as we discussed in person, the main thing is to not have a magic internal variable clash in public namespace with a common english word ("bucket"), I'm filing a pull request for the change even though your test case doesn't actually pass :).