我如何在Travis CI上运行Redis



我正在使用django

练习单元测试

在项目/tests.py

class NewBookSaleTest(SetUpLogInMixin):
def test_client_post_books(self):
    send_post_data_post = self.client.post(
            '/booksale/',
            data = {
                'title':'Book_A',
                }
            )
    new_post = ItemPost.objects.first()
    self.assertEqual(new_post.title, 'Book_A')

在视图/bookleale.py

class BookSale(LoginRequiredMixin, View):
login_url = '/login/'
def get(self, request):
    [...]
def post(self, request):
    title = request.POST.get('title')
    saler = request.user
    created_bookpost = ItemPost.objects.create(
                user=saler,
                title=title,
                )
    # redis + celery task queue
    auto_indexing = UpdateIndexTask()
    auto_indexing.delay()
        return redirect(
               [...]
                ) 

我运行单元测试时,提出redis连接错误

 redis.exceptions.ConnectionError

我知道何时运行redis服务器,而芹菜是错误将解决

但是,当我在Travis CI中运行单元测试时,我无法在Travis CI

中运行Redis服务器和芹菜

所以,我找到了这个链接

我尝试将此代码插入.travis.yml

language:
    python
python:
    - 3.5.1
addons:
    postgresql:"9.5.1"
install:
    - pip install -r requirement/development.txt
service:
    - redis-server
# # command to run tests
script:
    - pep8
    - python wef/manage.py makemigrations users items
    - python wef/manage.py migrate
    - python wef/manage.py collectstatic --settings=wef.settings.development --noinput
    - python wef/manage.py test users items --settings=wef.settings.development

但显示出相同的错误

所以我找到了下一个链接

before_script:
    - sudo redis-server /etc/redis/redis.conf --port 6379 --requirepass 'secret'

但是...显示出相同的错误...

如何在Travis CI中运行Redis-Server?

如果您现在还没有解决问题,这里有一个解决方案。

删除服务线。

redis由测试环境作为默认组件提供,因此

service:
    - redis-server

将被翻译为:

service redis start

在此问题中,我们要自定义redis添加密码auth。因此,我们不需要Travis CI来启动REDIS服务。只需使用before_script

毕竟,您的.travis.ym应该是这样的:

language:
    python
python:
    - 3.5.1
addons:
    postgresql:"9.5.1"
install:
    - pip install -r requirement/development.txt
before_script:
    - sudo redis-server /etc/redis/redis.conf --port 6379 --requirepass 'secret'
# # command to run tests
script:
    - pep8
    - python wef/manage.py makemigrations users items
    - python wef/manage.py migrate
    - python wef/manage.py collectstatic --settings=wef.settings.development --noinput
    - python wef/manage.py test users items --settings=wef.settings.development

相关内容

  • 没有找到相关文章

最新更新