]> arthur.barton.de Git - bup.git/blob - conftest.py
2f28334319e85df946cd243bc286492e60c47d8f
[bup.git] / conftest.py
1
2 from __future__ import absolute_import
3 from os.path import dirname, realpath
4 from time import tzset
5 import os
6 import pytest
7 import sys
8
9 sys.path[:0] = ['lib']
10
11 from bup import helpers
12 from bup.compat import environ, fsencode
13
14
15 _bup_src_top = realpath(dirname(fsencode(__file__)))
16
17 # The "pwd -P" here may not be appropriate in the long run, but we
18 # need it until we settle the relevant drecurse/exclusion questions:
19 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
20 os.chdir(realpath(os.getcwd()))
21
22 @pytest.fixture(autouse=True)
23 def ephemeral_env_changes():
24     orig_env = environ.copy()
25     yield None
26     for k, orig_v in orig_env.items():
27         v = environ.get(k)
28         if v is not orig_v:
29             environ[k] = orig_v
30             if k == b'TZ':
31                 tzset()
32     for k in environ.keys():
33         if k not in orig_env:
34             del environ[k]
35             if k == b'TZ':
36                 tzset()
37     os.chdir(_bup_src_top)