tests: adapt strings encoding to run tests in python3 (#40012)

This commit is contained in:
Nicolas Roche 2020-02-19 14:09:21 +01:00
parent 6da1e63aab
commit 825939d23b
1 changed files with 9 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import mock
import os
from django.core.management import BaseCommand, call_command, load_command_class
from django.utils.encoding import force_bytes
from django.utils import six
pytestmark = pytest.mark.django_db
@ -74,11 +76,11 @@ def test_tenant_command_all_tenants_errors(tenants, monkeypatch, capsys):
class BytesErrorCommand(BaseCommand):
def handle(self, *args, **kwargs):
raise Exception(b'héhé')
raise Exception(force_bytes('héhé'))
class MixOfBothCommand(BaseCommand):
def handle(self, *args, **kwargs):
raise Exception([b'héhé', u'hého'])
raise Exception([force_bytes('héhé'), u'hého'])
class WtfExceptionCommand(BaseCommand):
def handle(self, *args, **kwargs):
@ -115,13 +117,16 @@ def test_tenant_command_all_tenants_errors(tenants, monkeypatch, capsys):
klass.run_from_argv(['manage.py', 'tenant_command', 'bytes-error', '--all-tenants'])
captured = capsys.readouterr()
assert u'héhé' in captured.err
if six.PY2:
assert u'héhé' in captured.err
else:
assert repr(force_bytes('héhé')) in captured.err
with pytest.raises(SystemExit):
klass.run_from_argv(['manage.py', 'tenant_command', 'mix-error', '--all-tenants'])
captured = capsys.readouterr()
assert repr(b'héhé') in captured.err
assert repr(force_bytes('héhé')) in captured.err
assert repr(u'hého') in captured.err
with pytest.raises(SystemExit):