From 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Wed, 3 Feb 2021 19:17:00 -0500 Subject: New upstream version 8.1.2. --- tests/integration/conftest.py | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/integration/conftest.py (limited to 'tests/integration/conftest.py') diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 0000000..a87cb07 --- /dev/null +++ b/tests/integration/conftest.py @@ -0,0 +1,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 -- cgit v1.2.3