conftest.py 2.0 KB

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