Sat Mar 18 11:28:15 2006

Ticket #14 (Closed: fixed)

test generators for methods do not work


Priority: normal Reporter: guest
Severity: normal Assigned to: jpellerin
Component: nose Status: closed
Version: 0.8.7.1 Resolution: fixed
Milestone: 0.9a1 Keywords:  

Description by guest:

Given the following testclass:

class TestSomething(object):

def setUp(cls):

cls.x = 5 print "setting up"

def test_1(self):

assert self.x == 4

def test_2(self):

assert self.x == 6

def test_3(self):

for x in (1,2,7):

yield self.check,x

def check(self,arg):

assert arg %7 ==0

Method test_3 does not function as a proper test generator. What should probably happen is:

1) test_3 generates three separate tests, just like regular test generators 2) Each of the three tests created by test_3 should get setUp() called when they're called.

Attachments

  • core.py (35 kB) - Patch against 0.8.7.1 to add support for generator methods, added by guest on Sat Mar 18 12:11:25 2006.
  • added_method_generators (3 kB) - IGNORE LAST PATCH, I uploaded the wrong file before. *This* one adds support against 0.8.7.1, added by guest on Sat Mar 18 12:12:13 2006.
  • new_generator_patch (3 kB) - Fix over previous patch, use this instead of the last patch, added by guest on Mon Mar 20 13:11:16 2006.

Changelog

Sat Mar 18 12:06:46 2006: Modified by jpellerin

  • component changed from nose to nose:collector
  • milestone set to 0.9
  • version set to 0.9
  • status changed from new to assigned

Sat Mar 18 12:11:25 2006: Modified by guest

  • attachment added: core.py

Sat Mar 18 12:12:13 2006: Modified by guest

  • attachment added: added_method_generators

Mon Mar 20 13:10:42 2006: Modified by guest

  • component changed from nose:collector to nose
  • version changed from 0.9 to 0.8.7.1

The last patch I submitted had a problem doing the following:

class Testclass(object):

def setUp(self):

self.x = 1

def test_builder(self):

for each in (1,2,3)

yield self.check, each

def check(self, arg):

assert self.x == 1

Namely, the generator method 'check' couldn't access instance attributes in the previous patch. The new patch 'new_generator_patch' fixes this. Essentially, the original patch was creating the generator methods from an instance that was getting thrown away, and not properly creating a new instance for each generator method.

Mon Mar 20 13:11:16 2006: Modified by guest

  • attachment added: new_generator_patch

Thu Mar 23 20:51:16 2006: Modified by jpellerin

  • milestone changed from 0.9 to 0.9a1

This should roll up in the refactoring in #23.

Mon Apr 10 21:20:12 2006: Modified by jpellerin

    Generator methods should match generator funcs in their output, that is, the description of the test should include the generator method name, not the yielded method name.

    Mon Apr 10 21:51:13 2006: Modified by jpellerin

    • resolution set to fixed
    • status changed from assigned to closed

    Added, with tests (more coverage needed), in [21]