【发布时间】:2020-07-20 01:29:00
【问题描述】:
当我在与我的测试 VS 代码相同的文件中包含 BaseTestCase 时,测试资源管理器能够识别我的测试。
文件夹结构
MyProject/
app/
test/
myworking_test.py
base.py
mynotworking_test.py
myworking_test.py 这个可以通过 VS 代码资源管理器进行识别
import unittest
class BaseTestCase(unittest.TestCase):
def setUp(self):
self.num = 1
def tearDown(self):
self.num = None
class MyTest(BaseTestCase):
def runTest(self):
self.assertEqual(self.num, 1)
如果我将其拆分为 2 个文件,其中 BaseTestCase 是另一个文件并在另一个文件中进行测试,那么我该如何配置它。
base.py
import unittest
class BaseTestCase(unittest.TestCase):
def setUp(self):
self.num = 1
def tearDown(self):
self.num = None
mynotworking_test.py
from test.base import BaseTestCase
class MyTest(BaseTestCase):
def runTest(self):
self.assertEqual(self.num, 1)
根据以下建议更新:
【问题讨论】:
-
这些文件的位置是什么?阅读有关 python
import语句的信息。 -
@rioV8 我已经更新了上面的描述,请检查。我想我已经修复了 import 语句,但仍然无法在测试资源管理器中运行。
-
@rioV8 我还更新了问题描述中的示例代码。
-
为什么你的仓库中有
__pycache__?它是生成的东西。 -
是的,我没有添加 gitignore 以便添加该文件。
标签: python visual-studio-code vscode-settings