aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/conftest.py
blob: a87cb07780aa9d9c0532fd04909df85c65e9713d (plain) (blame)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sys

import docutils
import pytest

from nikola.utils import LocaleBorg
from ..helper import FakeSite


@pytest.fixture(scope="module")
def test_dir():
    """
    Absolute path to the directory with the tests.
    """
    return os.path.abspath(os.path.dirname(__file__))


@pytest.fixture(scope="session")
def other_locale() -> str:
    return os.environ.get("NIKOLA_LOCALE_OTHER", "pl")


@pytest.fixture(scope="module")
def output_dir(target_dir):
    return os.path.join(target_dir, "output")


@pytest.fixture(scope="module")
def target_dir(tmpdir_factory):
    tdir = tmpdir_factory.mktemp("integration").join("target")
    yield str(tdir)


@pytest.fixture(scope="module", autouse=True)
def remove_conf_module():
    """
    Remove the module `conf` from `sys.modules` after loading the config.

    Fixes issue #438
    """
    try:
        yield
    finally:
        try:
            del sys.modules["conf"]
        except KeyError:
            pass


@pytest.fixture(scope="module", autouse=True)
def localeborg_setup(default_locale):
    """
    Reset the LocaleBorg before and after every test.
    """
    LocaleBorg.reset()
    LocaleBorg.initialize({}, default_locale)
    try:
        yield
    finally:
        LocaleBorg.reset()


@pytest.fixture(autouse=True, scope="module")
def fix_leaked_state():
    """Fix leaked state from integration tests"""
    try:
        yield
    finally:
        try:
            func = docutils.parsers.rst.roles.role("doc", None, None, None)[0]
            func.site = FakeSite()
        except AttributeError:
            pass