conftest.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os.path
  2. import sys
  3. # This is a hack to fix path problems because "borg" (the package) is in the source root.
  4. # When importing the conftest an "import borg" can incorrectly import the borg from the
  5. # source root instead of the one installed in the environment.
  6. # The workaround is to remove entries pointing there from the path and check whether "borg"
  7. # is still importable. If it is not, then it has not been installed in the environment
  8. # and the entries are put back.
  9. #
  10. # TODO: After moving the package to src/: remove this.
  11. original_path = list(sys.path)
  12. for entry in original_path:
  13. if entry == '' or entry == os.path.dirname(__file__):
  14. sys.path.remove(entry)
  15. try:
  16. import borg
  17. except ImportError:
  18. sys.path = original_path
  19. from borg.logger import setup_logging
  20. # Ensure that the loggers exist for all tests
  21. setup_logging()
  22. from borg.testsuite import has_lchflags, no_lchlfags_because, has_llfuse
  23. from borg.testsuite.platform import fakeroot_detected
  24. from borg import xattr
  25. def pytest_report_header(config, startdir):
  26. yesno = ['no', 'yes']
  27. flags = 'Testing BSD-style flags: %s %s' % (yesno[has_lchflags], no_lchlfags_because)
  28. fakeroot = 'fakeroot: %s (>=1.20.2: %s)' % (
  29. yesno[fakeroot_detected()],
  30. yesno[xattr.XATTR_FAKEROOT])
  31. llfuse = 'Testing fuse: %s' % yesno[has_llfuse]
  32. return '\n'.join((flags, llfuse, fakeroot))