conftest.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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, constants
  25. def pytest_configure(config):
  26. # no fixture-based monkey-patching since star-imports are used for the constants module
  27. constants.PBKDF2_ITERATIONS = 1
  28. def pytest_report_header(config, startdir):
  29. yesno = ['no', 'yes']
  30. flags = 'Testing BSD-style flags: %s %s' % (yesno[has_lchflags], no_lchlfags_because)
  31. fakeroot = 'fakeroot: %s (>=1.20.2: %s)' % (
  32. yesno[fakeroot_detected()],
  33. yesno[xattr.XATTR_FAKEROOT])
  34. llfuse = 'Testing fuse: %s' % yesno[has_llfuse]
  35. return '\n'.join((flags, llfuse, fakeroot))