5

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.

4
  • This looks like an interaction of some Astropy pytest plugin with the test environment. I'm not sure how it's automatically getting discovered, but it's not just you. Commented Jun 8, 2016 at 13:16
  • Check if you have a conftest.py that imports astropy plugins. That's what it was in my project. Commented Jun 8, 2016 at 15:14
  • Thank you, that resolved my problem... Commented Jun 10, 2016 at 14:57
  • @josePhoenix - I couldn't quite understand your explanation but I think I've worked it out and I've added my answer below. Is this correct? Thanks. Commented Oct 18, 2016 at 19:30

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

My fault. Indeed the problem only appears if the folder contains no Python script. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.