|
- # -*- coding: utf-8 -*-
- """
- Conftest Fixtures
-
- pytest looks for conftest.py modules throughout the directory structure. Each
- conftest.py provides configuration for the file tree pytest finds it in. You can
- use any fixtures that are defined in a particular conftest.py throughout the file’s
- parent directory and in any subdirectories. This is a great place to put your most
- widely used fixtures.
- """
- from __future__ import (
- absolute_import,
- division,
- print_function,
- with_statement,
- unicode_literals,
- )
-
- import logging
- import os
-
- import mock
- import pytest
-
-
- logger = logging.getLogger(__name__) # pylint: disable=invalid-name
-
- FIXTURE_PATH = "{}/fixtures".format(os.path.dirname(os.path.abspath(__file__)))
-
-
- @pytest.fixture
- def os_path_mock(monkeypatch):
- """Disable looking up actual paths."""
-
- def _return_same(arg):
- return arg
-
- def _expand_user_mock(path):
- if not path.startswith("~"):
- return path
- if path == "~":
- return "/home/user"
- return "/home/{}".format(path[1:])
-
- os_path_mock = mock.Mock()
- attrs = {
- "expanduser.side_effect": _expand_user_mock,
- "realpath.side_effect": _return_same,
- "abspath.side_effect": _return_same,
- }
- os_path_mock.configure_mock(**attrs)
-
- return os_path_mock
|