Generate a Python package project using the Python Cookiecutter package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 satır
1.3KB

  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