【发布时间】:2020-08-25 14:41:42
【问题描述】:
当我将我的测试和 src 文件放在不同的子文件夹中时,我在测试文件的 from 行上遇到编译错误:"Unable to import 'classA' pylint(import-error)。当 src 和测试文件位于同一目录中时,它正在工作。这让我觉得这与 settings.json 文件有关,但我不确定。关于如何解决它的任何想法?
repo
├── .vscode
│ └── settings.json
├── src
│ ├── classA.py
│ └── classB.py
└── tests
├── classA_test.py
└── classB_test.py
classA.py:
from datetime import date
class fetchData():
var = ""
def __init__(self, thing):
self.var = thing
def getInfo(self, x):
..process things..
return info
classA_test.py
import unittest
from classA import fetchData
class classA(unittest.TestCase):
def testStuff(self):
..testStuff..
settings.json
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"*_test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
【问题讨论】:
标签: python unit-testing class visual-studio-code python-import