Как исправить 'TypeError: isinstance () arg 2 должен быть типом или кортежем типов' во время выполнения тестов в django в docker на окнах - PullRequest
1 голос
/ 05 июня 2019

Я недавно переехал в докер.Мое приложение работает прямо сейчас.Я запускаю тест python manage.py в моем проекте.Но я получил тонны ошибок «TypeError: isinstance () arg 2 должен быть типом или кортежем типов».

Такая же настройка работает под Linux-машиной.И сейчас я использую Windows 10 один.Основной образ докера - ubuntu14.04, использующий python версии 3.5.2, вот мой стоп-кадр:

amqp==2.5.0
atomicwrites==1.3.0
attrs==19.1.0
Babel==2.7.0
backcall==0.1.0
billiard==3.5.0.2
celery==4.1.0
decorator==4.4.0
dictdiffer==0.5.0.post1
dicttoxml==1.6.6
Django==2.0.2
django-common-helpers==0.9.2
django-cron==0.5.0
django-model-utils==3.0.0
django-params==0.3
django-pipeline==1.6.8
django-pytest==0.2.0
django-ranged-response==0.2.0
django-redis==4.8.0
django-simple-captcha==0.5.9
django-widget-tweaks==1.4.1
djangorestframework==3.7.7
et-xmlfile==1.0.1
factory-boy==2.8.1
Faker==0.7.7
fakeredis==0.8.2
flower==0.9.2
importlib-metadata==0.17
ipdb==0.12
ipython==7.5.0
ipython-genutils==0.2.0
jdcal==1.4.1
jedi==0.13.3
Jinja2==2.10.1
JPype1==0.6.1
kombu==4.1.0
lxml==3.6.0
MarkupSafe==1.1.1
more-itertools==7.0.0
openpyxl==2.4.1
packaging==19.0
parso==0.4.0
pathlib2==2.3.3
pexpect==4.7.0
pickleshare==0.7.5
Pillow==2.7.0
pluggy==0.12.0
prompt-toolkit==2.0.9
psycopg2==2.7.5
ptyprocess==0.6.0
py==1.8.0
Pygments==2.4.2
pyparsing==2.4.0
pytest==4.6.2
pytest-django==3.5.0
python-dateutil==2.8.0
pytz==2016.3
redis==2.10.6
reportlab==3.3.0
six==1.12.0
sqlparse==0.1.0
tornado==5.1.1
traitlets==4.3.2
vine==1.3.0
wcwidth==0.1.7
xlwt==1.1.2
zipp==0.5.1

self = <django.db.models.fields.DateTimeField: created_at>, value = datetime.datetime(2019, 6, 5, 16, 23, 2, 463090)

    def to_python(self, value):
        if value is None:
            return value
>       if isinstance(value, datetime.datetime):
E       TypeError: isinstance() arg 2 must be a type or tuple of types

/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py:1353: TypeError

, а вот полный след

Traceback (most recent call last):
  File "/code/app/app/test_api.py", line 19, in setUp
    self.user= UserFactory(role=User.ROLE_ADMIN, is_superuser=True)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 69, in __call__
    return cls.create(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 622, in create
    attrs = cls.attributes(create=True, extra=kwargs)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 453, in attributes
    force_sequence=force_sequence,
  File "/usr/local/lib/python3.5/dist-packages/factory/containers.py", line 324, in build
    return stub.__fill__()
  File "/usr/local/lib/python3.5/dist-packages/factory/containers.py", line 83, in __fill__
    res[attr] = getattr(self, attr)
  File "/usr/local/lib/python3.5/dist-packages/factory/containers.py", line 108, in __getattr__
    val = val.evaluate(self, self.__containers)
  File "/usr/local/lib/python3.5/dist-packages/factory/containers.py", line 227, in evaluate
    containers=containers,
  File "/usr/local/lib/python3.5/dist-packages/factory/declarations.py", line 324, in evaluate
    return self.generate(sequence, obj, create, defaults)
  File "/usr/local/lib/python3.5/dist-packages/factory/declarations.py", line 412, in generate
    return subfactory.simple_generate(create, **params)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 709, in simple_generate
    return cls.generate(strategy, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 676, in generate
    return action(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 623, in create
    return cls._generate(True, attrs)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 548, in _generate
    obj = cls._prepare(create, **attrs)
  File "/usr/local/lib/python3.5/dist-packages/factory/base.py", line 523, in _prepare
    return cls._create(model_class, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/factory/django.py", line 181, in _create
    return manager.create(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 417, in create
    obj.save(force_insert=True, using=self.db)
  File "/code/clinica/audit_track/models.py", line 32, in save
    super(UpdatedAtMixin, self).save(*args, **kwargs)
  File "/code/clinica/audit_track/models.py", line 98, in save
    super(CreatedByMixin, self).save(*args, **kwargs)
  File "/code/clinica/audit_track/models.py", line 116, in save
    super(UpdatedByMixin, self).save(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 729, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 759, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 842, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 880, in _do_insert
    using=using, raw=raw)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 1125, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 1280, in execute_sql
    for sql, params in self.as_sql():
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 1233, in as_sql
    for obj in self.query.objs
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 1233, in <listcomp>
    for obj in self.query.objs
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 1232, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 1172, in prepare_value
    value = field.get_db_prep_save(value, connection=self.connection)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 767, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 1431, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 1410, in get_prep_value
    value = super().get_prep_value(value)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 1271, in get_prep_value
    return self.to_python(value)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 1353, in to_python
    if isinstance(value, datetime.datetime):
TypeError: isinstance() arg 2 must be a type or tuple of types

1 Ответ

0 голосов
/ 05 июня 2019

В моей ситуации. У меня есть тест, где дата и время издеваются вручную. Если тест не пройден, насмешка не закрывается правильно. Мой совет, не ограничивайте прокручиваемый буфер вашего терминала при запуске тестов и исследуйте неудачные тесты с самого начала.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...