草庐IT

Autospec

全部标签

python - 使用unittest.mock.patch时,为什么autospec默认不是True?

当您使用mock修补函数时,您可以选择将autospec指定为True:Ifyousetautospec=Truethenthemockwithbecreatedwithaspecfromtheobjectbeingreplaced.Allattributesofthemockwillalsohavethespecofthecorrespondingattributeoftheobjectbeingreplaced.MethodsandfunctionsbeingmockedwillhavetheirargumentscheckedandwillraiseaTypeErrorifthe

python - 使用unittest.mock.patch时,为什么autospec默认不是True?

当您使用mock修补函数时,您可以选择将autospec指定为True:Ifyousetautospec=Truethenthemockwithbecreatedwithaspecfromtheobjectbeingreplaced.Allattributesofthemockwillalsohavethespecofthecorrespondingattributeoftheobjectbeingreplaced.MethodsandfunctionsbeingmockedwillhavetheirargumentscheckedandwillraiseaTypeErrorifthe

python - 如何在未模拟的类中使用 autospec 修补类方法?

我想断言Python类中的一个类方法使用一组特定的参数调用另一个类方法。我希望模拟的类方法是“规范的”,因此它会检测是否使用错误数量的参数调用它。当我使用patch.object(..,autospec=True,..)修补类方法时,类方法被替换为NonCallableMagicMock并在以下情况下引发错误我尝试调用它。frommockimportpatchclassA(object):@classmethoddefapi_meth(cls):returncls._internal_classmethod(1,2,3)@classmethoddef_internal_classmet

监视文件夹内文件更改的 linux 脚本(就像 autospec 一样!)

我想在文件更改时自动启动构建。我在Ruby中使用过autospec(RSpec)并且喜欢它。如何在bash中做到这一点? 最佳答案 看看incron和inotify-tools. 关于监视文件夹内文件更改的linux脚本(就像autospec一样!),我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/2972765/

ruby-on-rails - Factory Girl 序列在 autospec 下失败

我有这个工厂:Factory.define:email_addressdo|e|e.sequence(:address){|n|"factory_#{n}@example.com"}e.validatedtrueend当我使用rakespec运行我的规范时,它工作正常。当我运行autospec时,它立即失败,声称电子邮件地址在两个不同的对象中被使用了两次(有一个验证限制了这一点)。为什么它在autospec下表现不同? 最佳答案 有时,当您使用Ctrl+C中止测试套件时,可能会使您的数据库变脏。由于您的数据库很脏,创建新对象将发生验

ruby - Autospec/rspec 不工作,做错了什么?

我想知道这是否在StackOverflow上有它的位置,但由于它与编程相关,我会把它扔掉。这是我的问题。我是TDD的新手,我喜欢Ruby,所以我走的明显路径是用rspec测试东西。为什么明显?我在不同的截屏视频中看到它,并认为它非常简洁。然后我在某处看到“autospec”,并尝试使用它。所以我安装了gem,使用sudogeminstallZenTest(根据说明here)接下来,我进入包含“digit.rb”和“digit_spec.rb”的文件夹,并在没有任何参数的情况下启动autospec。什么都没发生。值得注意的是,我的spec文件中有两个测试,我可以使用spec命令对其进行测