我在PyCharm和nosetest集成中反复出现过各种形式的问题。
右键单击无法识别某些测试,或者类/模块根本不包含测试。
我已经搜索了很多很多SO答案,但仍然没有找到答案。
以下是该问题的当前复制品。测试的内容并不真正相关,但是它正在测试数据库接口周围的单例包装器。
class MyDBTest(unittest.TestCase):
def setup(self):
self.db = db_utils.get_connection(constants)
def teardown(self):
db_utils.truncate_all_my_tables(self.db)
self.db.commit()
self.db.close()
def test_same_instance(self):
other_instance = db_utils.get_connection(constants)
assert other_instance is self.db
def test_basic_query(self):
cur = self.db.cursor()
sql = "SELECT %s"
cur.execute(sql, "Test")
assert cur.rowcount == 1, "Expected one row, got <{0!s}>".format(cur.rowcount)
def test_reopen_connection(self):
self.db.close()
self.db = db_utils.get_connection(constants)
cur = self.db.cursor()
sql = "SELECT %s"
cur.execute(sql, "Test")
assert cur.rowcount == 1, "Expected one row, got <{0!s}>".format(cur.rowcount)
如果我右键点击测试&#34; test_basic_query&#34;我得到了上下文菜单选项:&#34;运行Nosetest test_basic_query&#34;并点击它确实运行测试,包括设置和拆解。
然而,右键单击其他测试只会显示&#34;运行test_db_wrapper&#34;选项。右键单击“项目”窗格中的文件也只提供此选项。
使用nosetests3可执行文件从命令行运行此文件甚至更奇怪。它运行所有三个测试,但不运行设置和拆卸。
注意我已尝试重新排序,重命名测试。我试过从object,nothing或unittest.TestCase继承。我有其他测试类看起来完全像这样,他们工作。
这只是一个例子,这种情况一直发生在我们身上。它似乎是随机的。
PyCharm版本是: PyCharm Community Edition 2016.1.4 Build#PC-145.1504,建于2016年5月25日 JRE:1.8.0_76-release-b198 amd64 JVM:JetBrains s.r.o的OpenJDK 64位服务器VM
答案 0 :(得分:2)
到目前为止,我发现了阻止上述情况的事情:
答案 1 :(得分:0)