簡體   English   中英

當 tox 安裝要求時定義超時

[英]Define timeout when tox is installing requirements

我有一個 gitlab ci 管道,它基本上在環境中做一些事情(安裝 python 和其他包)然后它只是運行tox以運行一些測試。

stages:
  - check



before_script:
    # here you can run any commands before the pipelines start
    - apt-get -qq update && apt-get -qq install -y python3.9
    - apt-get install -y libpq-dev &&  apt-get install -y python3.9-dev
    - apt-get install -y build-essential && apt-get install -y gcc && apt-get install -y postgresql
    - apt-get install -y  postgresql-contrib && apt-get install -y  ffmpeg libsm6 libxext6
    - apt-get install -y git
    - pip install tox



check:
  stage: check
  image: gitlab.*****.com:****/*****
  environment: prod
  services:
    - name: docker:19.03.8-dind #20.10.7
      alias: docker
  only:
    - master
  script:
    - |
      echo "
      machine gitlab.*****.com
      login gitlab-ci-token
      password $CI_JOB_TOKEN
      " > ~/.netrc 
    - tox

這是我的tox.ini

[tox]
envlist =
    {python3.9}


[testenv]
passenv = *
setenv =
    AIRFLOW_HOME = /airflow_home
deps=
    pytest
    -r{toxinidir}/requirements.txt 
commands=
    pytest 

問題是當tox構建環境並安裝requirements.txt中指定的包時,它返回ReadTimeOutError

我試圖刪除tox並簡單地運行pip install -r requirem.nets --default-timeout=200並且它有效。
所以問題似乎是超時。 我想定義一個timeout ,但我不想丟棄毒物。

我該怎么做?

tox 在后台使用 pip,因此您可以使用相同的選項,最好作為環境變量。

因此,在https://pip.pypa.io/en/stable/topics/configuration/#environment-variables 之后,您需要將--default-timeout轉換為PIP_DEFAULT_TIMEOUT變量。

您可以通過在 CI 中設置它然后在tox.ini中使用passenv指令來使用此變量,或者您可以通過setenv指令直接在tox.ini中設置它。

tox的相關文檔:

您可以更改默認install_command

install_command = pip install {opts} --default-timeout=200 {packages}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM