remove testing/__init__.py
AbandonedPublic

Authored by kparal on Apr 29 2014, 1:03 PM.

Details

Reviewers
None
Summary

I'm not sure I understand it very well, but those two sites are quite
convincing that there should not be __init__.py inside testing/
directory.

[1] says:

avoid “__init__.py” files in your test directories. This way your
tests can run easily against an installed version of mypkg,
independently from the installed package if it contains the tests or
not.

[2] says:

installed-versus-checkout version. py.test collects test modules on
the filesystem and then tries to import them under their fully
qualified name. This means that if your test directory contains an
init__.py file then your py.test invocation may end up importing the
package from the checkout directory rather than the installed package.
Therefore it is better to try to avoid
init__.py files in test
directories and also try to avoid custom PYTHONPATH settings. After
all, it is the job of your setup.py file and the install tools to care
for making the package properly available for importing.

[1] https://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules
[2] http://tox.readthedocs.org/en/0.9/example/pytest.html

Test Plan

Tests still pass.

Diff Detail

Branch
feature/testing__init__
Lint
No Linters Available
Unit
No Unit Test Coverage

If I try this on a clean checkout (virtualenv or not), it explodes.

$ py.test testing/
Traceback (most recent call last):
  File "/usr/bin/py.test", line 9, in <module>
    load_entry_point('pytest==2.4.2', 'console_scripts', 'py.test-2.7')()
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 18, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 63, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 368, in __call__
    return self._docall(methods, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 379, in _docall
    res = mc.execute()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 297, in execute
    res = method(**kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/helpconfig.py", line 25, in pytest_cmdline_parse
    config = __multicall__.execute()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 297, in execute
    res = method(**kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 618, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 711, in parse
    self._preparse(args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 691, in _preparse
    args=args, parser=self._parser)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 368, in __call__
    return self._docall(methods, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 379, in _docall
    res = mc.execute()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 297, in execute
    res = method(**kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/capture.py", line 42, in pytest_load_initial_conftests
    return __multicall__.execute()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 297, in execute
    res = method(**kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 674, in pytest_load_initial_conftests
    self._conftest.setinitial(args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 487, in setinitial
    self._try_load_conftest(anchor)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 493, in _try_load_conftest
    self._path2confmods[None] = self.getconftestmodules(anchor)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 512, in getconftestmodules
    clist.append(self.importconftest(conftestpath))
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 538, in importconftest
    self._conftestpath2mod[conftestpath] = mod = conftestpath.pyimport()
  File "/usr/lib/python2.7/site-packages/py/_path/local.py", line 621, in pyimport
    __import__(modname)
  File "/home/tflink/code/libtaskotron/libtaskotron-noinit/testing/conftest.py", line 25, in <module>
    import libtaskotron.config
ImportError: No module named libtaskotron.config
kparal planned changes to this revision.May 5 2014, 2:50 PM

I'll need to investigate. Moving back to my queue.

kparal updated this object.Jul 7 2014, 11:09 AM
kparal abandoned this revision.Jul 7 2014, 11:12 AM

I don't want to spend time with this, we don't seem to have any problems even when we have __init__.py inside the dir. Abandoning the patch. We can get back to it if we discover some issues.