我试图将SqlSoup移植到python3,我使用PyCharm作为我的IDE,我想运行单元测试。
如果我在py魅力中运行单元测试,就会得到以下输出:
C:\bin\python\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.3\helpers\pycharm\utrunner.py" C:\Users\jdearing\Documents\deleteme\sqlsoup\tests\test_sqlsoup.py true
Testing started at 12:53 PM ...
Error
Traceback (most recent call last):
File "C:\Users\jdearing\Documents\deleteme\sqlsoup\tests\test_sqlsoup.py", line 25, in setUp
engine.execute(sql)
NameError: name 'engine' is not defined但是,如果我从命令行运行测试,那么一切都很好:
C:\Users\jdearing\Documents\deleteme\sqlsoup>c:\bin\python\Scripts\nosetests-3.4.exe tests\test_sqlsoup.py
.............................
----------------------------------------------------------------------
Ran 29 tests in 0.549s
OK归根结底,这个方法从未被调用过:
@classmethod
def setup_class(cls):
global engine
engine = create_engine('sqlite://', echo=True)
for sql in _ddl:
engine.execute(sql)是的,这是一个全局变量,我将在运行它们之后改进单元测试。
Pycharm要求我安装鼻子以满足依赖性,所以我假设它的测试运行程序使用的是该模块,而不是另一个模块。为什么会产生不同的结果呢?
发布于 2015-01-26 22:31:57
据我所知,在测试类开始时,鼻子的设置必须是用于拾取和运行的以下格式:
@classmethod
def setUpClass(cls):
global engine
...https://stackoverflow.com/questions/27846637
复制相似问题