我想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,3 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"]
關于可能發生什么的任何想法?我沒有傳遞任何標志或引數,在這兩種情況下(主機或 docker),它只是一個原始的pytest.
我想也許當測驗失敗時,它會報告錯誤并且容器正在退出(即使我沒有使用pytest -x),但事實并非如此。運行所有測驗。
uj5u.com熱心網友回復:
您可以將您的存盤.pytest_cache在一個卷中,以便每次啟動新容器時,它都知道以前的運行。
例如,使用 compose。
services:
app:
image: myapp
command: python -m pytest -v --failed-first
volumes: [ pytest_cache:/app/.pytest_cache ]
volumes:
pytest_cache:
uj5u.com熱心網友回復:
這很容易解決。有一個丟失的檔案需要復制到容器中,其中包括:
[tool:pytest]
testpaths=tests
python_files=*.py
addopts = --junitxml=./reports/junit.xml
--verbose
--capture=no
--ignore=setup.py
--reruns 2 <----------------
--exitfirst
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/382124.html
