我在我的 Django 项目中使用 CircleCI。我想在后台运行服务器(特别是 python manage.py runserver
)以进行一些特定的 selenium 测试。
我的config.yml
有点像
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.1-browsers
- image: selenium/standalone-chrome
working_directory: ~/myproject
steps:
- checkout
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- run:
name: run unit tests
command: |
. venv/bin/activate
python manage.py test
- run:
name: run selenium tests
command: |
. venv/bin/activate
python manage.py migrate
python manage.py runserver 8000
python manage.py run_selenium_tests
我可以通过在 django LiveServerTestCase
中运行 selenium 测试来让它工作。但是我想独立运行 selenium 测试,因为我需要 runserver 在后台运行。现在 circleci 在 python manage.py runserver
停止执行并最终超时。有什么想法吗?
最佳答案
您需要将服务器启动为 background command .或者,您也可以使用 cURL 等待服务器准备就绪。
根据您发布的配置,您可以执行以下操作:
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.1-browsers
- image: selenium/standalone-chrome
working_directory: ~/myproject
steps:
- checkout
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- run:
name: run unit tests
command: |
. venv/bin/activate
python manage.py test
- run:
name: run selenium tests prep
command: |
. venv/bin/activate
python manage.py migrate
- run:
name: run server
command: python manage.py runserver 8000
background: true
- run:
name: run selenium tests
command: |
curl --retry-delay 5 --retry 10 --retry-connrefused http://localhost:8000
python manage.py run_selenium_tests
curl 语句在继续之前等待端口响应。这使您的服务器有时间完全启动。
- 里卡多·费利西亚诺
CircleCI 开发人员布道师
关于python - 如何使用 CircleCI 在后台运行服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45594861/