Search code examples
pythondictionarysetnosetests

Dictionary magically converted to set in nosetests


I have created following nose test:

@nottest
def _test_validate_helper_eq(self, input, expected, *args, **kwargs):
    result = testedObcject.validatePrice(input, *args, **kwargs)
    eq_(result, expected)


def test_validate_price(self):
    yield self._test_validate_helper_eq, {}, {'price':'0'}
    yield self._test_validate_helper_eq, {}, {'price', -1}, 'price', -1`

validatePrice is a function of tested object:

def validatePrice(self, input, name = 'price', default_price=0):
  ...
  return validated_input

So I've got a test generator that produces 2 tests using _test_validate_helper_eq function. Also _test_validate_helper_eq function takes various number of parameters and passes it to validatePrice

First test PASS, but there is a problem with second one. As you can see I am passing there additional 2 parameters, name and default_price. This test fails with following error: AssertionError: {'price': u'-1'} != set(['price', -1])

It turns out that value of expected parameter is a set instead of dictionary I have defined. I don't know if this convertion is made by nose or becaue *args and **kwargs are used.

Any ideas what is going on and how to fix it?


Solution

  • Typo in:

    yield self._test_validate_helper_eq, {}, {'price', -1}, 'price', -1`
    

    here {'price', -1} creates a set, you want a dict and probably meant to type {'price': -1}