Skip to content

with_data misguidely prepends the fixture to *args which breaks unittest.TestCase instance usage. #17

@rgammans

Description

@rgammans

I believe the following test should pass :-

import fixture
import unittest

class TestFixt (fixture.loadable.LoadableFixture):
    '''Create an empty fixture class which doesn't apply anything'''
    def attach_storage_medium(self,ds): pass
    def rollback(self,): pass
    def commit(self,): pass 

dbfixture = TestFixt()

fixture_tables = []

class SillyTests(unittest.TestCase):

    @dbfixture.with_data(*fixture_tables)
    def test_something_inane(self,fixt =None):
        self.assertNotEqual(fixt,None,"Fixture not applied")



if __name__ == "__main__":
    unittest.main()

However instead of passing in raises an exception AttributeError: <SuperSet at 0x1389690 with keys []> has no attribute 'assertNotEqual' this is due to the fixture being prepending to args (rather than the more usual append) and taking the of the self parameter.

I'd suggest changing the with_data to append , but that risks breaking existing users, so I suggets one of two possibilities.

  1. A new decorator which is identical to with_data but appends, rather than prepends the fixture,
  2. Modifying with_data to insert the fixture after the first argument if the first argument exists and and is an instance of unittest.Testcase .

I think overall I prefer the first but I've got some PoC code for the second.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions