uber / doubles

Test doubles for Python.
MIT License
164 stars 17 forks source link

Doubling a constructor leaks to other test file #60

Closed rajeshucsb closed 9 years ago

rajeshucsb commented 9 years ago

I have following test in a file, which worked fine

def test_valid_message_checkr(self):
 """Test lock works and locked message is not submitted"""

allow(module).is_enabled_city.and_return(False)

consumer = InstanceDouble('bgc.lib.kafka.Consumer')
with no_builtin_verification():
  allow(module.Consumer).__new__.and_return(consumer)

  allow(consumer).get_envelopes.and_return(
      [ujson.dumps(self.kafka_bgc_log)],
  )

  allow(consumer).lock_message.and_return(False)

  expect(application).submit.never()

  module.main()

Somehow this results in totally unrelated failure in other file

_ TestConsumer.test_getenvelopes Traceback (most recent call last):

File "/home/uber/background-check/env/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
return func(*args, **keywargs)
File "/home/uber/background-check/bgc/tests/lib/kafka/kafka_consumer_test.py", line 26, in   test_get_envelopes
consumer = Consumer('background-check.submit', 42)
DeprecationWarning: object.new() takes no parameters
toddsifleet commented 9 years ago

@rajeshucsb what version are you using?

Mocking of new requires doubles to do a little bit of strange stuff, so I can see this happening. I will take a look.

rajeshucsb commented 9 years ago

It was on 1.0.4