kevin1024 / vcrpy

Automatically mock your HTTP interactions to simplify and speed up testing
MIT License
2.72k stars 389 forks source link

Unicode Warning: Unicode equal comparison #254

Closed crawln45 closed 8 years ago

crawln45 commented 8 years ago

Seems when url is unicode encoded. VCR throws a warning about it and fails the test with -rw flag. Also seems that cassettes can't be used more than once.

System: Ubuntu 15.10 64bit
python version 2.7.10
py.test --version
This is pytest version 2.9.1, imported from /home/crawln/git/Flexget/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
  pytest-capturelog-0.7 at /home/crawln/git/Flexget/lib/python2.7/site-packages/pytest_capturelog.pyc
  pytest-xdist-1.14 at /home/crawln/git/Flexget/lib/python2.7/site-packages/xdist/boxed.pyc
  pytest-xdist-1.14 at /home/crawln/git/Flexget/lib/python2.7/site-packages/xdist/looponfail.pyc
  pytest-xdist-1.14 at /home/crawln/git/Flexget/lib/python2.7/site-packages/xdist/plugin.pyc
  pytest-cov-2.2.1 at /home/crawln/git/Flexget/lib/python2.7/site-packages/pytest_cov/plugin.pyc

CannotOverwriteExistingCassetteException: No match for the request (<Request (GET) https://api-v2launch.trakt.tv/search?query=%D0%98%D0%B3%D1%80%D0%B0+%D0%BF%D1%80%D0%B5%D1%81%D1%82%D0%BE%D0%BB%D0%BE%D0%B2&type=show>) was found. Can't overwrite existing cassette (u'/home/crawln/git/Flexget/tests/cassettes/test_trakt.TestTraktShowLookup.test_alternate_language') in your current record mode (u'once').
--------------------------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------------------------
/home/crawln/git/Flexget/lib/python2.7/site-packages/vcr/matchers.py:35: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  return r1.query == r2.query
kevin1024 commented 8 years ago

Check out the docs on record modes. By default the cassette can only be used once, but if you would like it to be more than once there's a mode for that :)

liiight commented 8 years ago

did you even look at the error that was pasted? this is still very relevant

cvium commented 8 years ago

Just to add some context to @liiight's comment:

The request recorded in the cassette is the same as the one in our test, but it fails to match the cassette on Python 2, because of a type error. The mismatch is caused by a comparison between a unicode string and a str object ie. u'sóme unicøde string' == 'sóme unicøde string'.

It's been a long time since I examined the problem, but from what I recall, the problem is that you're not saving unicode objects properly in the cassette.

EDIT: The cassette matches in Python 3, so it's definitely not because of the "record mode".