首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pytest教程时出错

使用pytest教程时出错
EN

Stack Overflow用户
提问于 2015-07-14 15:19:49
回答 1查看 2.1K关注 0票数 4

我读到单元测试是一个出色的特性,它可以编写更好的代码,并断言某些目标代码的特性保持不变。所以我想用它..。

我正在我的Linux机器上使用Anaconda。

我开始使用pytest,通过使用手册的入门指南在他们的主页上。安装成功后,会出现第一个(意外)错误:

代码语言:javascript
复制
strpeter@linuxComputer:~$ py.test 
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.8 -- py-1.4.25 -- pytest-2.6.3
collected 0 items / 1 errors 

========================================================= ERRORS =========================================================
___________________________________________________ ERROR collecting . ___________________________________________________
anaconda/lib/python2.7/site-packages/py/_path/common.py:331: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
anaconda/lib/python2.7/site-packages/py/_path/common.py:377: in gen
    for p in self.gen(subdir):
anaconda/lib/python2.7/site-packages/py/_path/common.py:377: in gen
    for p in self.gen(subdir):
anaconda/lib/python2.7/site-packages/py/_path/common.py:377: in gen
    for p in self.gen(subdir):
anaconda/lib/python2.7/site-packages/py/_path/common.py:377: in gen
    for p in self.gen(subdir):
anaconda/lib/python2.7/site-packages/py/_path/common.py:367: in gen
    if p.check(dir=1) and (rec is None or rec(p))])
anaconda/lib/python2.7/site-packages/_pytest/main.py:628: in _recurse
    ihook.pytest_collect_directory(path=path, parent=self)
anaconda/lib/python2.7/site-packages/_pytest/main.py:166: in call_matching_hooks
    plugins = self.config._getmatchingplugins(self.fspath)
anaconda/lib/python2.7/site-packages/_pytest/config.py:688: in _getmatchingplugins
    plugins += self._conftest.getconftestmodules(fspath)
anaconda/lib/python2.7/site-packages/_pytest/config.py:521: in getconftestmodules
    mod = self.importconftest(conftestpath)
anaconda/lib/python2.7/site-packages/_pytest/config.py:554: in importconftest
    self._onimport(mod)
anaconda/lib/python2.7/site-packages/_pytest/config.py:674: in _onimportconftest
    self.pluginmanager.consider_conftest(conftestmodule)
anaconda/lib/python2.7/site-packages/_pytest/core.py:201: in consider_conftest
    if self.register(conftestmodule, name=conftestmodule.__file__):
anaconda/lib/python2.7/site-packages/_pytest/core.py:100: in register
    reg(plugin, name)
anaconda/lib/python2.7/site-packages/_pytest/config.py:613: in _register_plugin
    call_plugin(plugin, "pytest_configure", {'config': self})
anaconda/lib/python2.7/site-packages/_pytest/core.py:265: in call_plugin
    kwargs=kwargs, firstresult=True).execute()
anaconda/lib/python2.7/site-packages/_pytest/core.py:315: in execute
    res = method(**kwargs)
anaconda/lib/python2.7/site-packages/astropy/tests/pytest_plugins.py:78: in pytest_configure
    if not config.getoption('remote_data'):
anaconda/lib/python2.7/site-packages/_pytest/config.py:836: in getoption
    raise ValueError("no option named %r" % (name,))
E   ValueError: no option named u'remote_data'
                                                     DO *NOT* COMMIT!                                                     
================================================ 1 error in 2.77 seconds =================================================

我想了解这个愚蠢的错误从何而来,以及如何解决它。我在没有任何文件名的情况下执行程序py.test,并且没有名为__init.py__的文件,这是一个问题吗?好吧,我问这个问题感觉很傻,但是请认真对待这个问题,因为我在万维网上没有发现任何提示。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-18 19:19:22

我刚刚遇到了这个问题。当您从错误的目录运行pytest时就会出现这种情况,例如在安装之后您碰巧在哪里。

为了解决问题,

  • 创建一个新目录并将cd放入该目录
  • 在您的目录中创建test_sample.py文件,其内容与pytest教程相同
  • 现在运行命令pytest,您将看到教程中显示的结果。

我自己也是新手,但我相信pytest会从它的运行位置搜索目录结构,寻找测试。从错误的地方运行它,如果它看到一些它认为可能是测试的东西,就会得到一些奇怪的结果。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31410723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档