Python 3 Unitesting:在unix中的控制台中执行时出现“ModuleNotFoundError”

问题描述 投票:0回答:1

如果我编写了一个单元测试,如果我在IDE Pycharm中运行我的tests.py就会通过。但是,如果我使用控制台(在unix中)并启动unittest:

python3 tests / tests.py

我收到以下错误:

ModuleNotFoundError:没有名为'helpermodule'的模块

我的文件夹结构如下所示:folder structure

文件如下所示:

my test.朋友:

def add(x,y):
    return x+y

tests.朋友:

from helpermodule import Mytest
import unittest

我在这里错过了什么?我已经阅读了几个关于这个问题的帖子,但我找不到有效的解决方案。

python-3.x
1个回答
0
投票

如果有人有同样的问题,简单的解决方案是使用正确的参数调用test.py:

python3 -m unittest tests/tests.py

也可以看看:

https://docs.python.org/3/library/unittest.html#command-line-interface

© www.soinside.com 2019 - 2024. All rights reserved.