strpeter
strpeter

Reputation: 2764

Error using pytest tutorial

I read that unit-test is a brilliant feature to write better code and assert that the features of some target code stay the same. So I wanted to use it...

I am using Anaconda on my Linux machine.

I started using pytest by working through the manual's starter guide on their homepage. After a successful installation there appears a first (unintended) error:

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 =================================================

I would like to understand where this stupid error comes from and how I can resolve it. Is the problem that I execute the program py.test without any filename and that there is no file called __init.py__? OK I am feeling really stupid by asking this question but please take the question serious since I found no hint in the world wide web.

Upvotes: 5

Views: 3124

Answers (1)

BobbyG
BobbyG

Reputation: 566

I have just had this issue. It arises when you run pytest from the wrong directory, e.g. wherever you happen to be after you installed it.

To solve,

  • create a new directory and cd into that directory
  • create the file test_sample.py in your directory with content as per the pytest tutorial
  • now run the command pytest and you will see the result that is shown in the tutorial.

I'm new to this myself but I believe pytest searches the directory structure from where it is run looking for tests. Run it from the wrong place and you'll get some strange results if it sees something that it thinks might be a test.

Upvotes: 6

Related Questions