草庐IT

test-utils

全部标签

python - dir_util.copy_tree 在 shutil.rmtree 之后失败

我正在尝试将文件夹删除后复制到另一个文件夹:foriinrange(0,3):try:dir_util.remove_tree("D:/test2")#shutil.rmtree("D:/test2")print"removed"except:passdir_util.copy_tree("D:/test1","D:/test2")printiD:/test1包含一个名为test_file的空文件。如果我使用dir_util.remove_tree它工作正常,但在shutil.rmtree之后它只工作一次,在第二次迭代时失败。输出:removed0removedTraceback(mo

Python:复杂的列表理解,其中一个变量依赖于另一个变量(x for x in t[1] for t in tests)

我想做这样的事情:all=[xforxint[1]fortintests]测试看起来像:[("foo",[a,b,c]),("bar",[d,e,f])]所以我想得到结果all=[a,b,c,d,e,f]我的代码不工作,Python说:UnboundLocalError:localvariable't'referencedbeforeassignment有什么简单的方法可以做到这一点吗? 最佳答案 它应该反过来工作:all=[xfortintestsforxint[1]] 关于Pytho

python - 从 emacs 运行 py.test

如果正在编辑的文件的名称以test_开头,我希望C-cC-c运行py.test并在另一个缓冲区中显示输出,否则通常运行py-execute-buffer。我该怎么做?我在python模式下使用emacs23.1.1,可以从命令行访问py.test。 最佳答案 这还没有经过特别好的测试;这只是一个粗略的想法。(defunpy-do-it()(interactive)(if(string-match(rxbos"test_")(file-name-nondirectory(buffer-file-name)))(compile"py.t

python - "django.db.utils.ProgrammingError: relation "app_user "does not exist"在 manage.py 测试期间

我的设置:Django1.8.3python2.7.10Ubuntu14.04django-two-factor-auth==1.2.0当我运行pythonmanage.pytest时出现以下错误:Traceback(mostrecentcalllast):File"/src/venv/bin/django-admin.py",line5,inmanagement.execute_from_command_line()File"/src/venv/lib/python2.7/site-packages/django/core/management/__init__.py",line33

python - 无法在 Windows 上导入 distutils.dir_util

我正在尝试在Windows764位上使用distutils.dir_util。据我从各种谷歌搜索中收集到的信息,我可能需要单独安装一些distutils包?我确实有可用的基本distutils包,但是它似乎被精简了很多并且缺少许多组件。尝试研究distutils和windows总是引导我使用python构建脚本以及如何将distutils打包为可再发行python项目的一部分或构建我不感兴趣的EXE,我根本看不到从哪里获得它的任何牵引力代码来自。已经很久了,但是我想我是从MSI安装程序安装Python的,不确定其他方法是否常见。这是我的解释器输出:Python2.7.3(default

python - 默认跳过测试,除非 py.test 中存在命令行参数

我有一个持续2天的长期测试,我不想将其包含在常规测试运行中。我也不想键入命令行参数,这会在每次常规测试运行时取消选择它和其他测试。当我确实需要时,我更愿意选择默认取消选择的测试。我尝试将测试从test_longrun重命名为longrun并使用命令py.testmytests.py::longrun但这不起作用。 最佳答案 除了上面的pytest_configure解决方案,我还找到了pytest.mark.skipif。你需要将pytest_addoption()放入conftest.pydefpytest_addoption(p

python - django.db.utils.OperationalError : (1071, 'Specified key was too long; max key length is 767 bytes' )

我的模型:classCourse(models.Model):language=models.ForeignKey(Language)name=models.CharField(max_length=50,unique=True,default='course')title=models.CharField(max_length=1024,default='notitle')foreign_title=models.CharField(max_length=1024,default='notitle',blank=True)header=models.CharField(max_len

python导入paramiko报错 "cannot import name util"

我已经安装了paramiko模块。但是,当我尝试导入该模块时。我收到以下错误。importparamiko---------------------------------------------------------------------------ImportErrorTraceback(mostrecentcalllast)in()---->1importparamikoC:\Anaconda\lib\site-packages\paramiko\__init__.pyin()2829--->30fromparamiko.transportimportSecurityOpti

Python 文档测试 : skip a test conditionally

我知道如何使用#doctest:+SKIP跳过doctest,但我不知道如何根据运行时条件有时跳过测试.例如:>>>ifos.path.isfile("foo"):...open("foo").readlines()...else:...pass#doctest:+SKIP['hello','world']这就是我想做的事情。我也会接受运行测试的解决方案,但如果不满足条件(即无条件运行测试但修改预期结果),则将预期结果更改为带有回溯的异常。 最佳答案 如果您不想对输出进行测试,您可以返回一个特殊值。让我们调用_skip这个特殊值:如

python - 如果 py.test 的另一个测试失败,我该如何跳过测试?

假设我有这些测试函数:deftest_function_one():assert#etc...deftest_function_two():#shouldonlyruniftest_function_onepassesassert#etc.如何确保test_function_two仅在test_function_one通过时运行(我希望这是可能的)?编辑:我需要这个,因为测试二正在使用测试一验证的属性。 最佳答案 您可以使用名为pytest-dependency的pytest插件.代码可以是这样的:importpytest@pyte