在Docker中导入测试模块时ImportError

时间:2019-08-24 01:01:35

标签: python docker virtualenv pytest

当我在虚拟环境中运行以下Pytest命令时,它会成功

python3 -m pytest ./tests/unit/

但是如果我使用bash进入Docker容器并从/ code运行它,则会出现以下错误:

_ ERROR collecting tests/unit/components/parser/s_parser/a/a_parser_test.py _
ImportError while importing test module '/code/tests/unit/components/parser/s_parser/a/a_parser_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
ModuleNotFoundError: No module named 'code.tests'; 'code' is not a package
___ ERROR collecting tests/unit/components/rrunner/runner/runner_test.py ____
ImportError while importing test module '/code/tests/unit/components/rrunner/runner/runner_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
ModuleNotFoundError: No module named 'code.tests'; 'code' is not a package

Docker命令 docker run --rm --network host -v $(pwd):/code container bash

我在Docker的/ code目录和每个子目录中看到了 init .py。

0 个答案:

没有答案
相关问题