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

nose2 test generation breaks when using the exam helper library #217

Closed
NorthIsUp opened this issue Aug 4, 2014 · 2 comments
Closed

nose2 test generation breaks when using the exam helper library #217

NorthIsUp opened this issue Aug 4, 2014 · 2 comments
Labels

Comments

@NorthIsUp
Copy link

similiar situation as in #80, it seems that a test case is being instantiated, but then a different instance is actually being used when running the test method.

import exam
import unittest2


from exam import before


class SomeTest(exam.Exam, unittest2.TestCase):

    @before
    def before(self):
        # executes before test run
        self.before_id = id(self)
        print 'before_id', self.before_id

    def assert_ids(self):
        print 'test_id', id(self)
        self.assertEqual(self.before_id, id(self))

    def test_someting(self):
        self.assert_ids()

    def test_gen_something(self):
        print 'gen_id', id(self)
        for x in xrange(3):
            yield self.test_someting, ()
gen_id 4505929424
gen_id 4506129040
before_id 4506129808
test_id 4506129808
before_id 4506129296
test_id 4506129040
before_id 4506129488
test_id 4506129040
before_id 4506129680
test_id 4506129040
test_someting (test_foo.SomeTest) ... ok
test_gen_something:1
 (test_foo.SomeTest) ... ERROR
test_gen_something:2
 (test_foo.SomeTest) ... ERROR
test_gen_something:3
 (test_foo.SomeTest) ... ERROR

======================================================================
ERROR: test_gen_something:1
 (test_foo.SomeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/adam/src/tempest/test_foo.py", line 21, in test_someting
    self.assert_ids()
  File "/Users/adam/src/tempest/test_foo.py", line 18, in assert_ids
    self.assertEqual(self.before_id, id(self))
AttributeError: 'SomeTest' object has no attribute 'before_id'

======================================================================
ERROR: test_gen_something:2
 (test_foo.SomeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/adam/src/tempest/test_foo.py", line 21, in test_someting
    self.assert_ids()
  File "/Users/adam/src/tempest/test_foo.py", line 18, in assert_ids
    self.assertEqual(self.before_id, id(self))
AttributeError: 'SomeTest' object has no attribute 'before_id'

======================================================================
ERROR: test_gen_something:3
 (test_foo.SomeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/adam/src/tempest/test_foo.py", line 21, in test_someting
    self.assert_ids()
  File "/Users/adam/src/tempest/test_foo.py", line 18, in assert_ids
    self.assertEqual(self.before_id, id(self))
AttributeError: 'SomeTest' object has no attribute 'before_id'

----------------------------------------------------------------------
Ran 4 tests in 0.025s

FAILED (errors=3)
@NorthIsUp
Copy link
Author

this was an error in the exam lib in how it handled descriptors. it has been fixed.

edit: my bad, I this is still an issue. The exam bug fix was unrelated.

@NorthIsUp NorthIsUp reopened this Aug 22, 2014
@little-dude little-dude removed this from the 0.5.1 milestone Feb 29, 2016
@sirosen
Copy link
Collaborator

sirosen commented Jan 13, 2025

I believe the underlying cause of this is #533

Unfortunately, there's no real fix at this stage in nose2's lifecycle. That bug is a design issue with generator tests.

I'm closing as a duplicate at this stage. #533 will probably stay open forever, unless it is converted into documentation.

@sirosen sirosen closed this as completed Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@NorthIsUp @sirosen @little-dude and others