所以我尝试了很多东西(来自SO 和更多)让我的测试运行但没有任何效果这是我当前的代码:
test.py
我调用它来运行测试:python3 ./src/preprocess/python/test.py
import unittest
if __name__ == '__main__':
testsuite = unittest.TestLoader().discover('.')
unittest.TextTestRunner(verbosity=2).run(testsuite)
测试文件如下所示:
import unittest
from scrapes.pdf import full_path_to_destination_txt_file
print(full_path_to_destination_txt_file)
class PreprocessingTest(unittest.TestCase):
def path_txt_appending(self):
self.assertEqual(full_path_to_destination_txt_file(
"test", "/usr/test"), "/usr/test/test.txt")
if __name__ == '__main__':
unittest.main(verbosity=2)
但输出总是这样:
python3 ./src/preprocess/python/test.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
附加信息:
- 如您所见,我不是从我的根目录中调用它。test 文件夹在里面
./src/preprocess/python/test/
,里面有一个__init__.py
文件(在 test.py 级别上还有一个 init 文件) - 如果我必须编写所有测试的所有调用,我只想完成这个,这对我来说没问题
- 使用 -t 的自动搜索也不起作用,所以我认为使用 test.py 的更强大的方法会起作用......
- 使用这个框架是我必须遵循的要求
- test_preprocessing.py 位于 test 文件夹中,
from scrapes.pdf import full_path_to_destination_txt_file
scrapes 是与 test 处于同一级别的模块文件夹 - 当我直接在命令行中调用单个单元测试时,由于相对导入而失败。但是使用 test.py (显然)可以找到模块。
怎么了?