conftest.py 1.8 KB

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