python - Why does py.test pass a unittest when Pyunit and nosetest fail it (as expected)? -


i'm complete new starter when comes writing python unittests , know it's far far better , easier write tests before code thought i'd start contributing github project , fixing few small issues , giving go.

one issue fixing if argument wasn't given method, remove argument on server. should mention project client rest api. easy enough fix thought write test it.

the code of broken method included within class:

def edit_device(self, device, nickname=none, model=none, manufacturer=none):     data = {"nickname": nickname}     iden = device.device_iden     r = self._session.post("{}/{}".format(self.devices_url, iden), data=json.dumps(data)) 

i going use mock mock responses of rest api using documentation guide (it includes example responses).

the issue having have written test as:

@mock.patch('pushbullet.pushbullet.requests.session.get', side_effect=mocked_requests_get) @mock.patch('pushbullet.pushbullet.requests.session.post', side_effect=mocked_requests_post) class testpushbullet(object):      def test_edit_device_without_nickname(self, mock_get, mock_post):         pb = pushbullet.pushbullet("api_key")         device = pb.devices[0]         new_device = pb.edit_device(device)         assert new_device.nickname == device.nickname 

this seems work correctly, methods mocked_requests_get , mocked_requests_post called. if run test within eclipse pydev using pyunit run pytest - fails, expect. if run tests using nose fails, again perfect. if run test using py.test on command line, passes.

if use pytest.set_trace() first line in mocked_requests_post can print args , shows nickname in fact not none , still set on server (i.e. device.nickname assertion passes)

i can't life of me work out why py.test not picking change in json self._session.post. if change iden in url format, indeed pick change, changing data body not.

am doing intrinsically wrong? can't see why py.test pass , nose fail on same code.

edit: on command line i'm running py.test path/to/single_test_file.py , test file has single test method i've pasted above.

finally worked out, must have installed client package python previous deciding write tests. looks command line py.test therefore reading client package true source (via pip install) whereas ide reading development package had in eclipse.

solution remove package: pip uninstall <package> reinstall development package: pip install -e . (when in root development directory)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -