0

我正在尝试从 django-treebeard 运行以下测试

如果您知道自己在做什么,有一个默认禁用的测试可以告诉您环境中的最佳默认字母表。要运行测试,您必须启用 TREEBEARD_TEST_ALPHABET 环境变量:

$ TREEBEARD_TEST_ALPHABET=1 py.test -k test_alphabet

我通过 Docker 设置了 Django 和 PostgreSQL:

Dockerfile

FROM python:3

ENV PYTHONUNBUFFERED=1
ENV TREEBEARD_TEST_ALPHABET=1
ENV DATABASE_USER = "postgres"
ENV DATABASE_PASSWORD = "postgres"
ENV DATABASE_HOST = "db"
ENV DATABASE_USER_POSTGRES = "postgres"
ENV DATABASE_PORT_POSTGRES = 5432

WORKDIR /code

COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --dev --system

COPY . /code/

码头工人-compose.yml

version: "3.9"
   
services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

点文件

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "~=3.2"
djangorestframework = "*"
ulid2 = "*"
psycopg2 = "*"
django-lifecycle = "*"
django-filter = "*"
django-cors-headers = "*"
djangorestframework-simplejwt = "*"
django-allauth = "*"
dj-rest-auth = "*"
django-treebeard = "*"
djangorestframework-recursive = "*"

[dev-packages]
black = "*"
django-debug-toolbar = "*"
drf-yasg = "*"
coverage = "*"
pytest = "*"

[requires]
python_version = "3.9"

[pipenv]
allow_prereleases = true

和服务在我的前端和我的 django 测试中运行良好dbweb

我还继续将django -treebeard 解压缩到我的 Docker Web 服务中,因此返回docker-compose exec web dir以下内容:dataappconfigdjango-treebeard-master

Dockerfile    README.md  data                     htmlcov
Pipfile       app        django-treebeard-master  manage.py       
Pipfile.lock  config     docker-compose.yml

当我运行时,docker-compose exec web pytest -k alphabet_test我收到以下错误:

====================== test session starts =======================platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /code
collected 1149 items / 1149 deselected

======================== warnings summary ========================django-treebeard-master/treebeard/tests/test_treebeard.py:170     
  /code/django-treebeard-master/treebeard/tests/test_treebeard.py:170: PytestUnknownMarkWarning: Unknown pytest.mark.django_db - is 
this a typo?  You can register custom marks to avoid this warning 
- for details, see https://docs.pytest.org/en/stable/mark.html    
    @pytest.mark.django_db

...

django-treebeard-master/treebeard/tests/test_treebeard.py:3032    
  /code/django-treebeard-master/treebeard/tests/test_treebeard.py:3032: PytestUnknownMarkWarning: Unknown pytest.mark.django_db - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html   
    @pytest.mark.django_db

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============= 1149 deselected, 29 warnings in 14.53s =============

如何修复此PytestUnknownMarkWarning: Unknown pytest.mark.django_db错误以便我可以运行py.test -k test_alphabet测试?

4

0 回答 0