简体   繁体   English

在测试根目录上发现 Unittest 期间的 ImportError

[英]ImportError during Unittest discover on tests root directory

Running tests discover using these format works:运行测试发现使用这些格式有效:

python -m unittest discover tests/folder1/folder2 -v
python -m unittest discover tests/folder1

The issue happens when I'm running the discover tests on the root directory of the tests scripts.当我在测试脚本的根目录上运行发现测试时,就会出现问题。

python -m unittest discover tests  # raised ImportError

My project structure looks like this:我的项目结构如下所示:

project_name/
    src/
        __init__.py
        # modules
    tests/
        folder1/
            __init__.py
            folder2/
                # test scripts
                __init__.py
        __init__.py

Based on what I read on some related post, the issue was with the PATH.根据我在一些相关帖子上阅读的内容,问题出在 PATH 上。 but I already include the src path by running this command and the ImportError still occurs.但是我已经通过运行此命令包含了 src 路径,并且 ImportError 仍然发生。

export PYTHONPATH=$PYTHONPATH:$(pwd)/src

python version: 3.5.0 python 版本:3.5.0

prepending test_ to test folders fixed the issue.test_之前添加到测试文件夹解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM