草庐IT

trace_test

全部标签

python - 使用 pdb.set_trace() 时没有 readline 支持

我有一个运行Python2.6.X的应用程序。以交互模式启动Python解释器(使用或不使用virtualenv):readline支持工作(命令历史)。使用相同的Python解释器启动我的应用程序(virtualenv-ed或不):使用pdb.set_trace()时没有可用的readline支持:光标键不起作用。操作系统为Linux。 最佳答案 检查此配方以在pdb中启用readline支持http://code.activestate.com/recipes/498182-sane-tab-completion-in-pdb/

python - ipython ipdb,当通过 ipdb.set_trace() 调用时,在调试时不记得命令历史

如果我正常运行ipython,iPython确实会记住命令历史记录,例如在repl中测试基本的东西,但我希望能够从以前的调试session中提取调试命令,我正在通过简单地正常运行我的程序来进行调试,其中程序包含importipdbdefinfo(type,value,info):importtracebacktraceback.print_exception(type,value,info)ipdb.pm()importsyssys.excepthook=infotrace=ipdb.set_trace设置它以便我可以在我的程序中的任何地方编写trace()以便在我运行程序时在那里开始

Python3 + pytest + pytest 模拟 : Mocks leaking into other test functions breaking assertions?

注意:有关我的设置(python版本、模块等)的所有详细信息都列在问题底部。如果这个问题很明显,请提前致歉,但我已经为此苦苦挣扎了好几天。希望有人可以阐明一些新的观点。我正在为我的个人项目从unittest->pytest转换单元测试。以前我使用的是内置的unittest.mock模块,但现在我正在尝试使用pytest-mock插件。我有一种潜移默化的感觉,我的测试正在将模拟对象泄漏到彼此中。原因如下:高级细节:#PythonversionPython3.5.2#Pytestversion(andplugins)pytest==3.0.7pytest-benchmark==3.1.0a

python - 测试 : parametrize test cases from classes

我目前正在关注这个py.test示例,当我不使用类时它会成功,但是当我将测试用例引入类时我失败了。我设法编写的最小案例如下:importunittestimportpytestclassFixtureTestCase(unittest.TestCase):@pytest.mark.parametrize("test_input,expected",[("3+5",8),("2+4",6),("6*9",42),])deftest_1(self,a,b):self.assertEqual(a,b)不幸的是当我执行py.testtest_suite.py我收到错误信息:TypeError:

python - 测试 : parametrize test cases from classes

我目前正在关注这个py.test示例,当我不使用类时它会成功,但是当我将测试用例引入类时我失败了。我设法编写的最小案例如下:importunittestimportpytestclassFixtureTestCase(unittest.TestCase):@pytest.mark.parametrize("test_input,expected",[("3+5",8),("2+4",6),("6*9",42),])deftest_1(self,a,b):self.assertEqual(a,b)不幸的是当我执行py.testtest_suite.py我收到错误信息:TypeError:

python - py.test 测试 flask 寄存器,AssertionError : Popped wrong request context

我正在使用Flask进行注册和登录:fromflask.ext.security.viewsimportregister,loginclassRegister(Resource):defpost(self):returnregister()classLogin(Resource):defpost(self):returnlogin()api.add_resource(Login,'/login')api.add_resource(Register,'/register')然后我使用py.test来测试这个类:classTestAPI:deftest_survey(self,app):c

python - py.test 测试 flask 寄存器,AssertionError : Popped wrong request context

我正在使用Flask进行注册和登录:fromflask.ext.security.viewsimportregister,loginclassRegister(Resource):defpost(self):returnregister()classLogin(Resource):defpost(self):returnlogin()api.add_resource(Login,'/login')api.add_resource(Register,'/register')然后我使用py.test来测试这个类:classTestAPI:deftest_survey(self,app):c

python - py.test SetUp/TearDown 用于整个测试套件

我有一个Python包需要访问X11。我想使用Xvfb,这样我就不必在构建机器上安装真正的X11——在本例中是Hudson。所以,我想在py.test启动时启动一个Xvfb服务器,使用该服务器进行所有测试,然后关闭它。我该怎么做?注意:我可以在每个测试类的SetUp(TearDown)中启动(停止)一个Xvfb服务器,但这有两个问题:首先,它很浪费。其次,如果我正确终止服务器,或者我挂起的Xvfb进程不会死,则它不会工作,因为奇怪的X服务器上的致命IO错误0(成功)。这是使用xvfbwrapper如果有人感兴趣。 最佳答案 你可以使

python - py.test SetUp/TearDown 用于整个测试套件

我有一个Python包需要访问X11。我想使用Xvfb,这样我就不必在构建机器上安装真正的X11——在本例中是Hudson。所以,我想在py.test启动时启动一个Xvfb服务器,使用该服务器进行所有测试,然后关闭它。我该怎么做?注意:我可以在每个测试类的SetUp(TearDown)中启动(停止)一个Xvfb服务器,但这有两个问题:首先,它很浪费。其次,如果我正确终止服务器,或者我挂起的Xvfb进程不会死,则它不会工作,因为奇怪的X服务器上的致命IO错误0(成功)。这是使用xvfbwrapper如果有人感兴趣。 最佳答案 你可以使

Python Proportion 测试类似于 R 中的 prop.test

我正在寻找执行此操作的Python测试:>survivorscolnames(survivors)rownames(survivors)survivorssurviveddiednoseatbelt1781135seatbelt144347>prop.test(survivors)2-sampletestforequalityofproportionswithcontinuitycorrectiondata:survivorsX-squared=24.3328,df=1,p-value=8.105e-07alternativehypothesis:two.sided95percentc