簡體   English   中英

看起來 Pytest 在容器中運行時無法重新運行測試

[英]It looks like Pytest can't rerun tests when running in a container

我想在容器中運行pytest ,與在主機中運行pytest相比,我發現了不同的行為。 只是一個簡單的容器,沒有編排器或其他任何東西。

當我在主機級別運行pytest時,所有測試都通過了。 有些需要幾個RERUN ,但最后,他們通過了。

例如,對於 3 次測試的樣本,僅運行pytest的結果是3 passed, 2 rerun in 111.37 seconds

現在,如果不是在主機中運行它,而是構建一個映像並運行一個容器,結果總是類似於1 failed, 2 passed in 73.53 seconds ,或者實際上是1 failed 2 passed , 2 failed 1 passed的任何組合2 failed 1 passed3 failed

請注意在這種情況下如何沒有提及任何rerun操作?

該圖像沒有任何花哨的東西,它就像復制需求,測試並運行 pytest 一樣簡單。

FROM python:3.7-slim

WORKDIR /apptests

COPY requirements requirements
COPY tests tests

RUN pip install -r requirements/tests.txt

CMD ["pytest"]

關於可能發生的事情有什么想法嗎? 我沒有傳遞任何標志或參數,在這兩種情況下(主機或碼頭工人),它只是一個原始pytest

我認為也許當測試失敗時,它會報告錯誤並且容器正在退出(即使我沒有使用pytest -x ),但事實並非如此。 所有測試都運行。

您可以將.pytest_cache存儲在一個卷中,以便每次啟動一個新容器時,它都知道之前的運行情況。

例如,使用撰寫。

services:
  app:
    image: myapp
    command: python -m pytest -v --failed-first
    volumes: [ pytest_cache:/app/.pytest_cache ]

volumes:
  pytest_cache:

這很容易解決。 有一個丟失的文件需要復制到容器中,其中包括:

[tool:pytest]
testpaths=tests
python_files=*.py
addopts = --junitxml=./reports/junit.xml
          --verbose
          --capture=no
          --ignore=setup.py
          --reruns 2                <----------------
          --exitfirst

暫無
暫無

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

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