conftest.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import os
  2. import pytest
  3. from borg.logger import setup_logging
  4. # Ensure that the loggers exist for all tests
  5. setup_logging()
  6. from borg.testsuite import has_lchflags, has_llfuse
  7. from borg.testsuite import are_symlinks_supported, are_hardlinks_supported, is_utime_fully_supported
  8. from borg.testsuite.platform import fakeroot_detected, are_acls_working
  9. from borg import xattr, constants
  10. def pytest_configure(config):
  11. # no fixture-based monkey-patching since star-imports are used for the constants module
  12. constants.PBKDF2_ITERATIONS = 1
  13. @pytest.fixture(autouse=True)
  14. def clean_env(tmpdir_factory, monkeypatch):
  15. # avoid that we access / modify the user's normal .config / .cache directory:
  16. monkeypatch.setenv('XDG_CONFIG_HOME', tmpdir_factory.mktemp('xdg-config-home'))
  17. monkeypatch.setenv('XDG_CACHE_HOME', tmpdir_factory.mktemp('xdg-cache-home'))
  18. # also avoid to use anything from the outside environment:
  19. keys = [key for key in os.environ if key.startswith('BORG_')]
  20. for key in keys:
  21. monkeypatch.delenv(key, raising=False)
  22. def pytest_report_header(config, startdir):
  23. tests = {
  24. "BSD flags": has_lchflags,
  25. "fuse": has_llfuse,
  26. "root": not fakeroot_detected(),
  27. "symlinks": are_symlinks_supported(),
  28. "hardlinks": are_hardlinks_supported(),
  29. "atime/mtime": is_utime_fully_supported(),
  30. "modes": "BORG_TESTS_IGNORE_MODES" not in os.environ
  31. }
  32. enabled = []
  33. disabled = []
  34. for test in tests:
  35. if tests[test]:
  36. enabled.append(test)
  37. else:
  38. disabled.append(test)
  39. output = "Tests enabled: " + ", ".join(enabled) + "\n"
  40. output += "Tests disabled: " + ", ".join(disabled)
  41. return output