Все мои настройки работают отлично и не имеют проблем как таковых. Просто CircleCI не справляется с максимально простыми тестами. Я создал домашнюю страницу и написал для нее тест. Тест на локальной машине с Ubuntu проходит нормально с python manage.py runserver
, а также с pytest
. Также установка и настройка прекрасно работает в логах на CircleCI.
Буду признателен, если кто-нибудь укажет мне правильное направление.
Мой тест на Джанго:
from django.test import TestCase
from django.urls import reverse
class TestPage(TestCase):
def test_home_page_works(self):
response = self.client.get(reverse("home"))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "base.html")
self.assertContains(response, "APTA")
Мой CircleCI config.yml:
version: 2
jobs:
build:
docker:
# specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- image: circleci/python:3.6.2
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
- image: postgres:9.6
environment:
- POSTGRES_USER=root
- POSTGRES_DB=lims
working_directory: ~/repo
steps:
- checkout
- run:
name: Wait for db
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Install
command: |
python3 -m venv venv
. envs/test
pip install .[test]
- run:
name: Install dependencies
command: |
. venv/bin/activate
python --version
pip install -r requirements.txt
- run:
name: Collect static files
command: |
. venv/bin/activate
python apta/./manage.py collectstatic --noinput
- run:
name: Test
command: |
. venv/bin/activate
python apta/./manage.py migrate --noinput
pytest
- run:
name: Lint
command: |
. envs/test
flake8
- store_artifacts:
path: test-reports
destination: test-reports
Мой pytest.ini:
[pytest]
DJANGO_SETTINGS_MODULE=apta.settings
python_files = tests.py test_*.py
Ошибка в CircleCI:
apta/tests/test_views.py F [100%]
=================================== FAILURES ===================================
________________________ TestPage.test_home_page_works _________________________
self = <tests.test_views.TestPage testMethod=test_home_page_works>
def test_home_page_works(self):
> response = self.client.get(reverse("home"))
apta/tests/test_views.py:8:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.6/site-packages/django/test/client.py:535: in get
response = super().get(path, data=data, secure=secure, **extra)
venv/lib/python3.6/site-packages/django/test/client.py:347: in get
**extra,
venv/lib/python3.6/site-packages/django/test/client.py:422: in generic
return self.request(**r)
venv/lib/python3.6/site-packages/django/test/client.py:503: in request
raise exc_value
venv/lib/python3.6/site-packages/django/core/handlers/exception.py:34: in inner
response = get_response(request)
venv/lib/python3.6/site-packages/django/core/handlers/base.py:145: in _get_response
response = self.process_exception_by_middleware(e, request)
venv/lib/python3.6/site-packages/django/core/handlers/base.py:143: in _get_response
response = response.render()
venv/lib/python3.6/site-packages/django/template/response.py:106: in render
self.content = self.rendered_content
venv/lib/python3.6/site-packages/django/template/response.py:81: in rendered_content
template = self.resolve_template(self.template_name)
venv/lib/python3.6/site-packages/django/template/response.py:63: in resolve_template
return select_template(template, using=self.using)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
template_name_list = ['base.html'], using = None
def select_template(template_name_list, using=None):
"""
Load and return a template for one of the given names.
Try names in order and return the first template found.
Raise TemplateDoesNotExist if no such template exists.
"""
if isinstance(template_name_list, str):
raise TypeError(
'select_template() takes an iterable of template names but got a '
'string: %r. Use get_template() if you want to load a single '
'template by name.' % template_name_list
)
chain = []
engines = _engine_list(using)
for template_name in template_name_list:
for engine in engines:
try:
return engine.get_template(template_name)
except TemplateDoesNotExist as e:
chain.append(e)
if template_name_list:
> raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
E django.template.exceptions.TemplateDoesNotExist: base.html
venv/lib/python3.6/site-packages/django/template/loader.py:47: TemplateDoesNotExist
------------------------------ Captured log call -------------------------------
log.py 228 ERROR Internal Server Error: /
Traceback (most recent call last):
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 145, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 143, in _get_response
response = response.render()
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/template/response.py", line 106, in render
self.content = self.rendered_content
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/template/response.py", line 81, in rendered_content
template = self.resolve_template(self.template_name)
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/template/response.py", line 63, in resolve_template
return select_template(template, using=self.using)
File "/home/circleci/repo/venv/lib/python3.6/site-packages/django/template/loader.py", line 47, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: base.html
=========================== 1 failed in 0.85 seconds ===========================
Exited with code 1