nose2 icon indicating copy to clipboard operation
nose2 copied to clipboard

Layers cannot use Django's test case classes

Open thedrow opened this issue 12 years ago • 4 comments

Traceback (most recent call last):
  File "/home/omer/.virtualenvs/restapi/bin/nose2", line 9, in <module>
    load_entry_point('nose2==0.5.0', 'console_scripts', 'nose2')()
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/main.py", line 284, in discover
    return main(*args, **kwargs)
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/main.py", line 98, in __init__
    super(PluggableTestProgram, self).__init__(**kw)
  File "/home/omer/.pyenv/versions/2.7.6/lib/python2.7/unittest/main.py", line 95, in __init__
    self.runTests()
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/main.py", line 260, in runTests
    self.result = runner.run(self.test)
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/runner.py", line 53, in run
    executor(test, result)
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/runner.py", line 41, in <lambda>
    executor = lambda suite, result: suite(result)
  File "/home/omer/.pyenv/versions/2.7.6/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/home/omer/.pyenv/versions/2.7.6/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/home/omer/.pyenv/versions/2.7.6/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/suite.py", line 24, in run
    self.setUp()
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/suite.py", line 44, in setUp
    setup = self._getBoundClassmethod(self.layer, 'setUp')
  File "/home/omer/.virtualenvs/restapi/lib/python2.7/site-packages/nose2/suite.py", line 118, in _getBoundClassmethod
    'The %s method on a layer must be a classmethod.' % method)
TypeError: The setUp method on a layer must be a classmethod.

thedrow avatar Dec 02 '13 12:12 thedrow

I'm not sure what you tried here -- using a TestCase subclass as a layer? That won't work, by design -- layers aren't test cases, they are just a way to organize and share fixtures among test cases. I'm not sure what it would mean to have a layer that was also a test case. Would that mean the tests in the layer also get executed? IMO that's confusing and unnecessary and so I think the behavior here is correct.

jpellerin avatar Dec 02 '13 17:12 jpellerin

So how do you cause a layer to use Django TransactionTestCase features when you use Such instead of the classic TestCase?

thedrow avatar Dec 03 '13 08:12 thedrow

Perhaps we should provide layers that fit Django's test framework functionality. I'm not very fond of the idea since it's a maintenance burden to copy/paste the code with each Django release and it certainly won't support multiple Django versions.

thedrow avatar Dec 03 '13 08:12 thedrow

I think django-nose2 would be the right place for layer support to be added. And/or maybe Such could be extended to support passing an optional TestCase class into createTests?

On Tue, Dec 3, 2013 at 3:16 AM, Omer Katz [email protected] wrote:

Perhaps we should provide layers that fit Django's test framework functionality. I'm not very fond of the idea since it's a maintenance burden to copy/paste the code with each Django release and it certainly won't support multiple Django versions.

— Reply to this email directly or view it on GitHubhttps://github.com/nose-devs/nose2/issues/138#issuecomment-29690707 .

jpellerin avatar Dec 03 '13 15:12 jpellerin