File: conftest.py

package info (click to toggle)
sphinx-intl 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 340 kB
  • sloc: python: 1,162; makefile: 13
file content (49 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download
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
"""
    conftest
    ~~~~~~~~

    PyTest utilities.

    :copyright: Copyright 2019 by Takayuki SHIMIZUKAWA.
    :license: BSD, see LICENSE for details.
"""
import os

import pytest

from path import path

_dir = path(os.path.dirname(os.path.abspath(__file__)))


@pytest.fixture(scope="function")
def temp(request, tmpdir):
    template_dir = 'root'

    tmpdir = path(tmpdir)
    (_dir / template_dir).copytree(tmpdir / template_dir)
    cwd = os.getcwd()
    temp = tmpdir / template_dir
    os.chdir(temp)

    def fin():
        os.chdir(cwd)
    request.addfinalizer(fin)
    return temp


@pytest.fixture(scope="function")
def home_in_temp(request, tmpdir):
    """change HOME environment variable to temporary location

     To avoid real .transifexrc will be rewritten.
     """
    home = os.environ.get('HOME')
    os.environ['HOME'] = tmpdir.strpath

    def fin():
        del os.environ['HOME']
        if home:
            os.environ['HOME'] = home
    request.addfinalizer(fin)
    return tmpdir