草庐IT

foo_unittest

全部标签

java - Android,org.simpleframework.xml 持久化异常,元素 'foo' 已被使用

我正在使用org.simpleframework.xml来处理android应用程序的一些xml任务,但遇到了以下我无法弄清楚的错误。org.simpleframework.xml.core.PersistenceException:Element'album'isalreadyusedwith@org.simpleframework.xml.ElementList(inline=false,name=album,entry=,data=false,empty=true,required=true,type=void)onfield'albums'privatejava.util.Li

java - 为什么 foo(1,2,3) 没有作为 Integer[] 传递给可变参数方法 foo(Object...)

请注意以下代码行:publicstaticvoidmain(String[]args){foo(1,2,3);System.out.println("-------------------------------------");foo(newInteger(1),newInteger(2),newInteger(3));System.out.println("-------------------------------------");foo(newInteger[]{1,2,3});System.out.println("-----------------------------

python - 在键 "foo"后面插入 OrderedDict(就地)

这个问题在这里已经有了答案:HowtoaddanelementtothebeginningofanOrderedDict?(11个答案)关闭7年前。我想在OrdedDict中的给定键后面插入一个键。例子:my_orderded_dict=OrderedDict([('one',1),('three',3)])我希望'two'-->2进入正确的位置。在我的例子中,我需要就地更新OrdedDict。背景Django的SortedDict(它有一个insert())被移除:https://code.djangoproject.com/wiki/SortedDict

python - 如何在 Python argparse 中使用 `--foo 1 --foo 2` 样式参数?

nargs='+'没有按我预期的方式工作:>>>importargparse>>>parser=argparse.ArgumentParser()>>>parser.add_argument("--name",dest='names',nargs='+')_StoreAction(option_strings=['--name'],dest='names',nargs='+',const=None,default=None,type=None,choices=None,help=None,metavar=None)>>>parser.parse_args('--namefoo--nam

python - 有什么方法可以将自定义/调试消息添加到 python/django unittest.TestCase 的失败测试方法的详细信息中?

我正在使用unittest.TestCase为我的django应用程序编写测试用例(这与python中的unittest.TestCase基本相同)。每当测试方法失败时,我都会以下面的格式得到它的解释。有没有一种方法可以将自定义/调试消息添加到失败的测试方法的输出中?======================================================================FAIL:test_bad_votes(polls.tests.views.PollsViewsTestCase)-----------------------------------

python - 是否可以让 Nose 只运行 TestCase 或 TestSuite 子类的测试(如 unittest.main())

我的测试框架目前基于一个测试运行器实用程序,该实用程序本身派生自Eclipsepydevpython测试运行器。我转而使用Nose,它具有我的自定义测试运行程序的许多功能,但似乎是质量更好的代码。我的测试套件包括许多以前从未运行过的抽象测试类。标准的python测试运行器(和我的自定义测试运行器)只运行unittest.TestCase和unittest.TestSuite的实例。我注意到,自从我切换到Nose后,它几乎运行任何以名称“test”开头的东西,这很烦人......因为我们用于测试混合的命名约定看起来也像Nose的测试类.以前这些从未作为测试运行,因为它们不是TestCas

python - isinstance(foo, types.GeneratorType) 还是 inspect.isgenerator(foo)?

在Python中似乎有两种方法来测试一个对象是否是生成器:importtypesisinstance(foo,types.GeneratorType)或:importinspectinspect.isgenerator(foo)本着“应该有一种-最好只有一种-显而易见的方法”的精神,推荐这些方法中的一种而不是另一种(大概他们做同样的事情......如果不是,请赐教!)? 最佳答案 它们是100%等效的:>>>print(inspect.getsource(inspect.isgenerator))defisgenerator(obj

python - py.test : hide stacktrace lines from unittest module

py.test堆栈跟踪目前看起来像这样:Traceback(mostrecentcalllast):File"/home/foo_tbz_di476/src/djangotools/djangotools/tests/ReadonlyModelTestCommon.py",line788,intest_stale_or_missing_content_typesself.assertEqual([],errors,'Stale/MissingContentTypes:%s'%'\n'.join(errors))File"/usr/lib64/python2.7/unittest/cas

python - Pytest 适用于旧模拟,但不适用于 unittest.mock

我正在将一些代码从Python2移植到3,而py.test不能很好地与来自unittest.mockpatch装饰器一起玩。当我使用patch装饰器将模拟传递给测试函数的参数时,py.test反而将该参数解释为固定装置,并且无法设置测试。这里有一个人为的例子,希望能说明问题:@patch('my_module.my_func')deftest_my_func(mock_func):mock_func()mock_func.assert_called_once_with()运行py.test后,错误消息如下所示:Efixture'my_func'notfound>availablefix

python unittest assertRaises在assertRaises失败时抛出异常

我有一段代码,当assertRaises失败时,assertRaises抛出一个异常。我认为如果assertRaises失败,那么测试就会失败,最后我会得到一份报告,说测试失败。我没想到会抛出异常。下面是我的代码。我做错什么了吗?我正在使用Python2.6.2。importunittestclassmyClass:defgetName(self):raisemyExcOne,"myexceptionone"#raisemyExcTwo,"myexceptiontwo"#return"a"classmyExcOne(Exception):"exceptionone"classmyExc