Repository: borgbackup/borg

Issue:
tox testing on master branch broken
ac2617f6652880975d191c0cb44e881f3dcea83c broke it.

```
(borg-env)tw@tux:~/w/borg$ git checkout ac2617f6652880975d191c0cb44e881f3dcea83c
(borg-env)tw@tux:~/w/borg$ fakeroot -u tox -e py34
GLOB sdist-make: /home/tw/w/borg/setup.py
py34 inst-nodeps: /home/tw/w/borg/.tox/dist/borgbackup-1.0.3.dev208-ngac2617f.zip
py34 installed: The directory '/home/tw/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.,You are using pip version 7.1.2, however version 8.1.2 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,Attic==0.16,borgbackup===1.0.3.dev208-ngac2617f,coverage==4.0.3,Cython==0.24,msgpack-python==0.4.7,pluggy==0.3.1,py==1.4.31,pytest==2.9.1,pytest-benchmark==3.0.0,pytest-cov==2.2.1,tox==2.3.1,virtualenv==13.1.2,wheel==0.24.0
py34 runtests: PYTHONHASHSEED='3485813151'
py34 runtests: commands[0] | py.test --cov=borg --cov-config=../.coveragerc --benchmark-skip --pyargs borg.testsuite
Traceback (most recent call last):
  File "/home/tw/w/borg/.tox/py34/lib/python3.4/site-packages/_pytest/config.py", line 283, in _getconftestmodules
    return self._path2confmods[path]
KeyError: local('/home/tw/w/borg/.tox')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/tw/w/borg/.tox/py34/lib/python3.4/site-packages/_pytest/config.py", line 314, in _importconftest
    return self._conftestpath2mod[conftestpath]
KeyError: local('/home/tw/w/borg/conftest.py')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/tw/w/borg/.tox/py34/lib/python3.4/site-packages/_pytest/config.py", line 320, in _importconftest
    mod = conftestpath.pyimport()
  File "/home/tw/w/borg/.tox/py34/lib/python3.4/site-packages/py/_path/local.py", line 650, in pyimport
    __import__(modname)
  File "/home/tw/w/borg/conftest.py", line 6, in <module>
    from borg.testsuite import has_lchflags, no_lchlfags_because, has_llfuse
  File "/home/tw/w/borg/borg/testsuite/__init__.py", line 13, in <module>
    from ..platform import get_flags
  File "/home/tw/w/borg/borg/platform.py", line 6, in <module>
    from .platform_linux import acl_get, acl_set, SyncFile, set_flags, get_flags, API_VERSION
ImportError: No module named 'borg.platform_linux'
ERROR: could not load /home/tw/w/borg/conftest.py

ERROR: InvocationError: '/home/tw/w/borg/.tox/py34/bin/py.test --cov=borg --cov-config=../.coveragerc --benchmark-skip --pyargs borg.testsuite'
________________________________________________________________________ summary _________________________________________________________________________
ERROR:   py34: commands failed
```



Discussion:
it still worked with: 47d29e75b3c3cb44883e421977aaca1156724a07

I suppose #1050 broke that. Strange, it worked in the Vagrant VM also using tox. Hmm.

strange is that it works with -e py35.


Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -1,3 +1,24 @@
+import sys
+
+# This is a hack to fix path problems because "borg" (the package) is in the source root.
+# When importing the conftest an "import borg" can incorrectly import the borg from the
+# source root instead of the one installed in the environment.
+# The workaround is to remove entries pointing there from the path and check whether "borg"
+# is still importable. If it is not, then it has not been installed in the environment
+# and the entries are put back.
+#
+# TODO: After moving the package to src/: remove this.
+
+original_path = list(sys.path)
+for entry in original_path:
+    if entry == '' or entry.endswith('/borg'):
+        sys.path.remove(entry)
+
+try:
+    import borg
+except ImportError:
+    sys.path = original_path
+
 from borg.logger import setup_logging
 
 # Ensure that the loggers exist for all tests


Test patch: