diff options
author | Bobby Impollonia <bobbyi@gmail.com> | 2011-05-01 13:39:41 -0700 |
---|---|---|
committer | Bobby Impollonia <bobbyi@gmail.com> | 2011-05-01 13:39:41 -0700 |
commit | 0e2ef2befd4e35bf8488c066893d91ff15dd2ac0 (patch) | |
tree | 95ab01b94936b68b8a060447c0e12459889b614d /unit_tests | |
parent | dc095969fc322ff3e2ab70d6d70962021450c101 (diff) | |
download | nose-0e2ef2befd4e35bf8488c066893d91ff15dd2ac0.tar.gz |
Overhaul the Attribute Selector plugin to fix the following bugs:
Issue #412 : Attributes don't work on inherited test method
Issue #411 : Plugin doesn't work on classes containing static methods
Issue #324 : Mixing method and class attributes doesn't work
Issue #381 : Plugin doesn't work on classes containing methods with no __dict__ (e.g., from boost.python)
Issue #382 : Dupe of #381 with less info
* When used as class decorator, attr() was only applying the attributes to methods with names starting with "test_". It would skip, e.g., my_cool_test.
* The class decorator form of attr() did not work for test methods inherited from parent classes, nor were the attributes inherited by child classes. They also didn't work for methods added to the class later (e.g., by another decorator).
The primary changes are to use getattr/ setattr exlusively rather than direct access to __dict__ and to remove the (unneeded and problematic) wantClass method. Most of the bugs were caused by __dict__ access or wantClass not doing the right thing. In addition to fixing the above bugs, these changes make the plugin smaller and simpler to understand.
Add regression tests for fixed bugs.
Change
assert not plug.wantFunction(h)
to
assert plug.wantFunction(h) is False
where plug.wantFunction only return None or False
Refactor duplicated code in functional tests into base class.
Diffstat (limited to 'unit_tests')
-rw-r--r-- | unit_tests/test_attribute_plugin.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/unit_tests/test_attribute_plugin.py b/unit_tests/test_attribute_plugin.py index f9214f9..0df0e99 100644 --- a/unit_tests/test_attribute_plugin.py +++ b/unit_tests/test_attribute_plugin.py @@ -1,4 +1,4 @@ - +# There are more attribute plugin unit tests in unit_tests/test_plugins.py from nose.tools import eq_ from nose.plugins.attrib import attr @@ -31,6 +31,7 @@ def test_mixed(): eq_(test.role, 'integration') def test_class_attrs(): + # @attr('slow', 'net', role='integration') class MyTest: def setUp(): pass @@ -39,11 +40,14 @@ def test_class_attrs(): def test_two(self): pass + class SubClass(MyTest): + pass + MyTest = attr('slow', 'net', role='integration')(MyTest) - for n in ('test_one', 'test_two'): - eq_(getattr(MyTest, n).slow, 1) - eq_(getattr(MyTest, n).net, 1) - eq_(getattr(MyTest, n).slow, 1) + eq_(MyTest.slow, 1) + eq_(MyTest.net, 1) + eq_(MyTest.role, 'integration') + eq_(SubClass.slow, 1) assert not hasattr(MyTest.setUp, 'slow') -
\ No newline at end of file + assert not hasattr(MyTest.test_two, 'slow') |