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

Conflict with nose2? #18

Open
carldunham opened this issue Nov 15, 2016 · 8 comments
Open

Conflict with nose2? #18

carldunham opened this issue Nov 15, 2016 · 8 comments
Labels

Comments

@carldunham
Copy link

Running a simple test:

from unittest import TestCase
from flexmock import flexmock

class TestSomething(TestCase):
    def test_something(self):
        self.assertTrue(True)

without Twisted, the test passes. With Twisted installed (no other changes), get:

$ python -V
Python 3.5.0
$ pip install nose2 flexmock Twisted
$ pip freeze
constantly==15.1.0
flexmock==0.10.2
incremental==16.10.1
nose2==0.6.5
six==1.10.0
Twisted==16.5.0
zope.interface==4.3.2
$ nose2
Traceback (most recent call last):
  File "/Users/cdunham/.pyenv/versions/nose2-twisted-issue-3.5/bin/nose2", line 11, in <module>
    sys.exit(discover())
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/main.py", line 306, in discover
    return main(*args, **kwargs)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/main.py", line 100, in __init__
    super(PluggableTestProgram, self).__init__(**kw)
  File "/Users/cdunham/.pyenv/versions/3.5.0/lib/python3.5/unittest/main.py", line 93, in __init__
    self.parseArgs(argv)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/main.py", line 133, in parseArgs
    self.createTests()
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/main.py", line 258, in createTests
    self.testNames, self.module)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/loader.py", line 62, in loadTestsFromNames
    result = self.session.hooks.loadTestsFromNames(event)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/events.py", line 224, in __call__
    result = getattr(plugin, self.method)(event)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/discovery.py", line 250, in loadTestsFromNames
    return Discoverer.loadTestsFromNames(self, event)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/discovery.py", line 90, in loadTestsFromNames
    return self._discover(event)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/discovery.py", line 128, in _discover
    tests = list(self._find_tests(event, start_dir, top_level_dir))
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/discovery.py", line 140, in _find_tests
    event, full_path, top_level):
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/discovery.py", line 160, in _find_tests_in_dir
    event, path, entry_path, top_level):
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/discovery.py", line 217, in _find_tests_in_file
    yield loader.loadTestsFromModule(module)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/loader.py", line 43, in loadTestsFromModule
    result = self.session.hooks.loadTestsFromModule(evt)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/events.py", line 224, in __call__
    result = getattr(plugin, self.method)(event)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/testcases.py", line 48, in loadTestsFromModule
    self._loadTestsFromTestCase(event, obj))
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/testcases.py", line 75, in _loadTestsFromTestCase
    result = self.session.hooks.loadTestsFromTestCase(evt)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/events.py", line 224, in __call__
    result = getattr(plugin, self.method)(event)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/nose2/plugins/loader/generators.py", line 67, in loadTestsFromTestCase
    method = getattr(testCaseClass, name)
  File "/Users/cdunham/.pyenv/versions/3.5.0/envs/nose2-twisted-issue-3.5/lib/python3.5/site-packages/zope/interface/declarations.py", line 636, in __get__
    raise AttributeError('__provides__')
AttributeError: __provides__
$ pip uninstall Twisted
$ nose2
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
$ 
@bkabrda
Copy link
Collaborator

bkabrda commented Nov 17, 2016

Hi, thanks for the report, I can reproduce this and will look into it.

@bkabrda
Copy link
Collaborator

bkabrda commented Nov 17, 2016

Turns out this is not an issue in flexmock, in certain sense. If Twisted is installed, flexmock will try to hook up into twisted.trial, so it will try to import that. The backtrace that you reported actually shows if you try to import something from twisted.trial without having flexmock even installed:

from unittest import TestCase
from twisted.trial import reporter

class TestSomething(TestCase):
    def test_something(self):
        self.assertTrue(True)

I'm not familiar with nose2 enough to be able to tell which of the following is true:

  1. nose2 is wrong because it should work together with twisted.trial, so this should be fixed in nose2
  2. same as above, but perhaps this is issue in twisted.trial rather than in nose2
  3. they're not meant to work together, in which case the fault is on flexmock's side for running the hook and this has to be fixed on flexmock's side

I'll try to learn more about nose2 vs twisted.trial to be able to tell which one of the above cases this is and then act on it - either by reporting issue for nose2 or twisted or trying to figure out how to fix this on flexmock's side.

@carldunham
Copy link
Author

Interesting. It seems like not many people are using nose2. Not sure why

@carldunham
Copy link
Author

So I switched to nose and things work for me, so it seems like a nose2 discovery plugin issue

@bkabrda
Copy link
Collaborator

bkabrda commented Nov 18, 2016

Thanks, so at least you have a workaround for now. In the meanwhile, I'll try to get some time to investigate this further :)

@carldunham
Copy link
Author

Any update on this? Definitely seems like there are issues with nose2:

from unittest import TestCase
from flexmock import flexmock # noqa


class AClass(object):
    def foo(self):
        pass


class TestSomething(TestCase):

    def setUp(self):
        # flexmock(AClass).should_receive('foo').twice()
        self.foo = AClass()
        flexmock(self.foo).should_receive('foo').twice()

    def test_counting(self):
        self.foo.foo()

running this succeeds:

nose2 tests.test_flexmock
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

@carldunham carldunham changed the title Conflict with Twisted? Conflict with nose2? Jul 8, 2017
@carldunham
Copy link
Author

I think I see the issue. Nose2 has it's own TestResult class, to send events to plugins for stopTest, etc. So patching the unittest one makes no difference. It also lazy-loads and keeps TestCase instances around. I am thinking about writing a flexmock plugin for nose2, rather than adding another special case here.

@bkabrda
Copy link
Collaborator

bkabrda commented Jul 14, 2017

Hey, sorry for the late response here. I've been extremely busy both in work and personal life lately and didn't have any time to take care of flexmock. This should improve in the upcoming weeks, so I'll definitely get to this. Thanks for your patience.
Alternatively, you can just send a PR. From your description of the problem it seems entirely reasonable to have a flexmock plugin for nose2, so a contribution there would be very welcome!

@ollipa ollipa added the bug label Aug 15, 2021
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

3 participants