Git Lab CI使用SqlAlchemy运行鼻子测试.错误:失败:TypeError(无法将此__setattr__应用于DefaultMeta对象) [英] Git lab CI Running nose tests with SqlAlchemy. ERROR: Failure: TypeError (can't apply this __setattr__ to DefaultMeta object)

查看:205
本文介绍了Git Lab CI使用SqlAlchemy运行鼻子测试.错误:失败:TypeError(无法将此__setattr__应用于DefaultMeta对象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Postgres数据库开发Flask应用程序. 当我在本地运行鼻子测试时,一切正常,但是当我将代码上传到GitLab时,这发生在我的管道中.我正在使用gitlab-ci.欢迎提供任何有关解决此问题的建议.

I am working on a Flask Application with a Postgres database. When I run nose tests locally everything works fine, but when I upload the code to GitLab this happens in my pipeline. I am using gitlab-ci. Any suggestions on how to solve this issue are welcome.

$ nosetests --with-coverage --cover-package=app
EEEEE
======================================================================
ERROR: Failure: TypeError (can't apply this __setattr__ to DefaultMeta object)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/nose/loader.py", line 417, in loadTestsFromName
    module = self.importer.importFromPath(
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/local/lib/python3.8/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/local/lib/python3.8/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/builds/Mubangizi1/mobile_shop_backend/app/controllers/__init__.py", line 2, in <module>
    from .product import (ProductDetailView, ProductView)
  File "/builds/Mubangizi1/mobile_shop_backend/app/controllers/product.py", line 6, in <module>
    from app.models.product import Product
  File "/builds/Mubangizi1/mobile_shop_backend/app/models/__init__.py", line 3, in <module>
    db = SQLAlchemy()
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 715, in __init__
    self.Model = self.make_declarative_base(model_class, metadata)
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 797, in make_declarative_base
    model.query_class = self.Query
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/api.py", line 79, in __setattr__
    _add_attribute(cls, key, value)
  File "/builds/Mubangizi1/mobile_shop_backend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 802, in _add_attribute
    type.__setattr__(cls, key, value)
TypeError: can't apply this __setattr__ to DefaultMeta object
======================================================================
ERROR: Failure: TypeError (can't apply this __setattr__ to DefaultMeta object)
----------------------------------------------------------------------
.
.
.
Ran 5 tests in 0.550s
FAILED (errors=5)
ERROR: Job failed: exit code 1

这是我的.gitlab-ci.yml文件,其中包含管道配置.

This is my .gitlab-ci.yml file containing the pipeline configurations.

image: python:latest
# # Change pip's cache directory to be inside the project directory since we can
# # only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  
cache:
  paths:
    - .cache/pip
    - venv/

before_script:
  - python -V  # Print out python version for debugging
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate

stages:
  - test

test:
  stage: test
  services:
    - postgres:alpine
  variables:
    POSTGRES_DB: mobile_shop_test_db
    POSTGRES_USER: postgres
    POSTGRES_HOST: postgres
    POSTGRES_PORT: 5432
    POSTGRES_PASSWORD: password
  
  script:
    - export FLASK_APP=server.py
    - export FLASK_ENV=testing
    - export DATABASE_TEST_URI=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/mobile_shop_test_db
    - export FLASK_APP_SECRET=qY2i691SX2sEuZ7LUjY180RS98mw3qCeUiyV0i0vzmg
    - apt-get update -qy
    - apt-get install -y python-dev python-pip
    - pip install -r requirements.txt
    - nosetests --with-coverage --cover-package=app
    - codecov

推荐答案

这看起来像是python语言中引入的一个问题.

This looks like an issue that was introduced into the python language.

要解决此问题:

您可以还原正在构建的python的版本,或者,如果您使用的是docker,请使用python:3.8.3-slim或等效的图像临时修复python图像.您也可以等到修复程序出炉.

You can revert the version of python you are building with, or if you are using docker, fix the python image temporarily using python:3.8.3-slim or an equivalent image. You can also wait until the fix is out.

您可以在此处查看相关的请求请求: https://github.com/python/cpython/pull/21473

You can see the related pull request here: https://github.com/python/cpython/pull/21473

在这里介绍: https://bugs.python.org/issue39960

在此处修补错误: https://bugs.python.org/issue41295

不相关的程序包中的另一个问题是相同的错误: flask_sqlalchemy:__setattr__到DefaultMeta的错误

Another issue in an unrelated package that is the same error: flask_sqlalchemy: error with `__setattr__` to `DefaultMeta`

带有修复程序的较新版本已经发布.检出python:3.8.5 +

A newer version with the fix is out. Check out any image of python:3.8.5 +

这篇关于Git Lab CI使用SqlAlchemy运行鼻子测试.错误:失败:TypeError(无法将此__setattr__应用于DefaultMeta对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆