草庐IT

unittest++

全部标签

python - 在 Python unittest 框架中修改全局变量

我正在使用Python进行一系列单元测试,其中一些取决于配置变量的值。这些变量存储在全局Python配置文件中,并在其他模块中使用。我想为配置变量的不同值编写单元测试,但还没有找到方法。我无法重写我正在测试的方法的签名。这就是我想要实现的目标:frommy_moduleimportmy_function_with_global_varclassTestSomething(self.unittest):deftest_first_case(self):fromconfigimportMY_CONFIG_VARIABLEMY_CONFIG_VARIABLE=Trueself.assertE

python - 在 Python unittest 框架中修改全局变量

我正在使用Python进行一系列单元测试,其中一些取决于配置变量的值。这些变量存储在全局Python配置文件中,并在其他模块中使用。我想为配置变量的不同值编写单元测试,但还没有找到方法。我无法重写我正在测试的方法的签名。这就是我想要实现的目标:frommy_moduleimportmy_function_with_global_varclassTestSomething(self.unittest):deftest_first_case(self):fromconfigimportMY_CONFIG_VARIABLEMY_CONFIG_VARIABLE=Trueself.assertE

python - 为什么 unittest 中的断言使用 TestCase.assertEqual 而不是 assert 关键字?

Python的内置unittest模块使用TestCase.assert*方法进行断言:classFooTest(TestCase):deftest_foo(self):self.assertEqual(1,1)self.assertNotEqual(1,2)self.assertTrue(True)我通常使用测试运行器,例如nose或py.test允许在进行断言时使用内置的assert关键字:assert1==1assert1!=2assertTrueunittest的TestCase.assert*方法的动机是什么?这与使用内置assert关键字断言的优缺点是什么?是否有理由支持u

python - 为什么 unittest 中的断言使用 TestCase.assertEqual 而不是 assert 关键字?

Python的内置unittest模块使用TestCase.assert*方法进行断言:classFooTest(TestCase):deftest_foo(self):self.assertEqual(1,1)self.assertNotEqual(1,2)self.assertTrue(True)我通常使用测试运行器,例如nose或py.test允许在进行断言时使用内置的assert关键字:assert1==1assert1!=2assertTrueunittest的TestCase.assert*方法的动机是什么?这与使用内置assert关键字断言的优缺点是什么?是否有理由支持u

Python 单元测试 : Automatically Running the Debugger when a test fails

有没有办法在单元测试失败时自动启动调试器?目前我只是手动使用pdb.set_trace(),但这非常繁琐,因为我每次都需要添加它并在最后取出它。例如:importunittestclasstests(unittest.TestCase):defsetUp(self):passdeftest_trigger_pdb(self):#thisisthewayIdoitnowtry:assert1==0exceptAssertionError:importpdbpdb.set_trace()deftest_no_trigger(self):#thisisthewayIwouldliketodo

Python 单元测试 : Automatically Running the Debugger when a test fails

有没有办法在单元测试失败时自动启动调试器?目前我只是手动使用pdb.set_trace(),但这非常繁琐,因为我每次都需要添加它并在最后取出它。例如:importunittestclasstests(unittest.TestCase):defsetUp(self):passdeftest_trigger_pdb(self):#thisisthewayIdoitnowtry:assert1==0exceptAssertionError:importpdbpdb.set_trace()deftest_no_trigger(self):#thisisthewayIwouldliketodo

python - 单元测试未运行

我遇到了一些单元测试。这是我能想到的最简单的例子:#testito.pyimportunittestclassPrueba(unittest.TestCase):defsetUp(self):passdefprintsTrue(self):self.assertTrue(True)if__name__=="__main__":unittest.main()问题是,运行这个没有效果:$pythontestito.py----------------------------------------------------------------------Ran0testsin0.000s

python - 单元测试未运行

我遇到了一些单元测试。这是我能想到的最简单的例子:#testito.pyimportunittestclassPrueba(unittest.TestCase):defsetUp(self):passdefprintsTrue(self):self.assertTrue(True)if__name__=="__main__":unittest.main()问题是,运行这个没有效果:$pythontestito.py----------------------------------------------------------------------Ran0testsin0.000s

python ,单元测试: is there a way to pass command line options to the app

我有一个导入unittest并有一些TestCases的模块。我想接受一些命令行选项(例如下面的数据文件的名称),但是当我尝试传递选项时,我收到消息option-inotrecognized。是否可以让unittest+为应用程序提供选项(注意:我正在使用optparse来处理选项)?谢谢。$pythontest_app_data.py-idata_1.txtoption-inotrecognized======================跟进:这是建议解决方案的实现:importcfg_master#hastheoptparseoption-handlingcode...if__

python ,单元测试: is there a way to pass command line options to the app

我有一个导入unittest并有一些TestCases的模块。我想接受一些命令行选项(例如下面的数据文件的名称),但是当我尝试传递选项时,我收到消息option-inotrecognized。是否可以让unittest+为应用程序提供选项(注意:我正在使用optparse来处理选项)?谢谢。$pythontest_app_data.py-idata_1.txtoption-inotrecognized======================跟进:这是建议解决方案的实现:importcfg_master#hastheoptparseoption-handlingcode...if__