File: conftest.py

package info (click to toggle)
python-kajiki 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 692 kB
  • sloc: python: 4,145; makefile: 115
file content (25 lines) | stat: -rw-r--r-- 750 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import importlib
import pathlib
import sys

import pytest


@pytest.fixture(scope="session", autouse=True)
def add_test_data_module():
    here = pathlib.Path(__file__).parent
    data_package = here / "data" / "__init__.py"
    spec = importlib.util.spec_from_file_location("kajiki_test_data", str(data_package))

    # TODO(Python3.4): below dance can change to
    # importlib.util.module_from_spec() when support for Python 3.4 is
    # dropped.
    module = type(sys)(spec.name)
    module.__name__ = spec.name
    module.__loader__ = spec.loader
    module.__package__ = spec.parent
    module.__path__ = spec.submodule_search_locations
    module.__file__ = spec.origin

    sys.modules[spec.name] = module
    spec.loader.exec_module(module)