fixtures.py 688 B

123456789101112131415161718192021222324252627
  1. try:
  2. from unittest import mock
  3. except ImportError:
  4. import mock
  5. import pytest
  6. from . import contexts
  7. @pytest.yield_fixture
  8. def user_override():
  9. """
  10. Override site.USER_BASE and site.USER_SITE with temporary directories in
  11. a context.
  12. """
  13. with contexts.tempdir() as user_base:
  14. with mock.patch('site.USER_BASE', user_base):
  15. with contexts.tempdir() as user_site:
  16. with mock.patch('site.USER_SITE', user_site):
  17. with contexts.save_user_site_setting():
  18. yield
  19. @pytest.yield_fixture
  20. def tmpdir_cwd(tmpdir):
  21. with tmpdir.as_cwd() as orig:
  22. yield orig