This Question have no Text answers yet!

python/django MagicMock return return value not behaving like I expect


I havr this try/except loop in a model method that I am trying to write tests for...

    wiktionary_url = "" \
        % (self.language.wiktionary_prefix, url_sub_path,
    wiktionary_page = urllib2.urlopen(wiktionary_url)
    wiktionary_page = fromstring(
    file_url = wiktionary_page.xpath(
                "//*[contains(concat(' ', @class, ' '), ' fullMedia ')][email protected]")[0]
    file_number = self.get_num(
    print file_number + " file num"
    relative_path = '%s/%s%s.ogg' % (path,, file_number)
    full_path = '%s/%s' % (settings.MEDIA_ROOT, relative_path)
    popen("wget -q -O %s 'http:%s'" % (full_path, file_url))
    made = self.definition_set.all()[0].convert_to_mp3(full_path)
except Exception as exc:
    print str(exc)
    return False

and I am trying to write a test for it while mocking some of the function in it.

def test_get_wiktionary_audio(self, popen, convert_to_mp3, fromstring, urlopen):
    # I need to mock another function in the actual method
    fromstring.return_value = MagicMock(return_value='string')
    test = self.things.model['word'].get_wiktionary_audio('en')

when I try something similar in the python intepreter it works perfectly. but when this test runs it outputs this error.

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `wget -q -O /Users/Jeff/Development/langalang/langalang/../media/study_audio/eng/words/table1.ogg 'http:<MagicMock name='fromstring().xpath().__getitem__()' id='4361699216'>''

so my return value statements are not being read properly but I cannot see what is happening.

Video about python/django MagicMock return return value not behaving like I expect