Generate a Python package project using the Python Cookiecutter package
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

conftest.py 1.3KB

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