Generate a Python package project using the Python Cookiecutter package
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

conftest.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. Conftest Fixtures
  3. pytest looks for conftest.py modules throughout the directory structure. Each
  4. conftest.py provides configuration for the file tree pytest finds it in. You can
  5. use any fixtures that are defined in a particular conftest.py throughout the file’s
  6. parent directory and in any subdirectories. This is a great place to put your most
  7. widely used fixtures.
  8. """
  9. from __future__ import (
  10. absolute_import,
  11. division,
  12. print_function,
  13. unicode_literals,
  14. with_statement,
  15. )
  16. import logging
  17. import os
  18. import mock
  19. import pytest
  20. logger = logging.getLogger(__name__) # pylint: disable=invalid-name
  21. FIXTURE_PATH = "{}/fixtures".format(os.path.dirname(os.path.abspath(__file__)))
  22. @pytest.fixture
  23. def os_path_mock(monkeypatch):
  24. """Disable looking up actual paths."""
  25. def _return_same(arg):
  26. return arg
  27. def _expand_user_mock(path):
  28. if not path.startswith("~"):
  29. return path
  30. if path == "~":
  31. return "/home/user"
  32. return "/home/{}".format(path[1:])
  33. os_path_mock = mock.Mock()
  34. attrs = {
  35. "expanduser.side_effect": _expand_user_mock,
  36. "realpath.side_effect": _return_same,
  37. "abspath.side_effect": _return_same,
  38. }
  39. os_path_mock.configure_mock(**attrs)
  40. return os_path_mock