conftest.py 1.9 KB

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