ソースを参照

Improve robustness of monkey patching borg.constants.PBKDF2_ITERATIONS. And add lots of warnings.

Martin Hostettler 8 年 前
コミット
005068dd6d
2 ファイル変更10 行追加6 行削除
  1. 8 6
      conftest.py
  2. 2 0
      src/borg/__init__.py

+ 8 - 6
conftest.py

@@ -2,6 +2,13 @@ import os
 
 import pytest
 
+# IMPORTANT keep this above all other borg imports to avoid inconsistent values
+# for `from borg.constants import PBKDF2_ITERATIONS` (or star import) usages before
+# this is executed
+from borg import constants
+# no fixture-based monkey-patching since star-imports are used for the constants module
+constants.PBKDF2_ITERATIONS = 1
+
 # needed to get pretty assertion failures in unit tests:
 if hasattr(pytest, 'register_assert_rewrite'):
     pytest.register_assert_rewrite('borg.testsuite')
@@ -14,12 +21,7 @@ setup_logging()
 from borg.testsuite import has_lchflags, has_llfuse
 from borg.testsuite import are_symlinks_supported, are_hardlinks_supported, is_utime_fully_supported
 from borg.testsuite.platform import fakeroot_detected, are_acls_working
-from borg import xattr, constants
-
-
-def pytest_configure(config):
-    # no fixture-based monkey-patching since star-imports are used for the constants module
-    constants.PBKDF2_ITERATIONS = 1
+from borg import xattr
 
 
 @pytest.fixture(autouse=True)

+ 2 - 0
src/borg/__init__.py

@@ -1,5 +1,7 @@
 from distutils.version import LooseVersion
 
+# IMPORTANT keep imports from borg here to a minimum because our testsuite depends on
+# beeing able to import borg.constants and then monkey patching borg.constants.PBKDF2_ITERATIONS
 from ._version import version as __version__