File: fixtures.py

package info (click to toggle)
pytest-relaxed 2.0.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212 kB
  • sloc: python: 960; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 828 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
import os

from pytest import fixture


# TODO: consider making this a "no param/funcarg required" fixture (i.e. one
# that gets decorated onto test classes instead of injected as magic kwargs)
# and have uses of it simply call os.environ as normal. Pro: test code looks
# less magical, con: removes any ability to do anything more interesting with
# the yielded value (like proxying or whatever.) See the pytest 3.1.2 docs at:
# /fixture.html#using-fixtures-from-classes-modules-or-projects
@fixture
def environ():
    """
    Enforce restoration of current shell environment after modifications.

    Yields the ``os.environ`` dict after snapshotting it; restores the original
    value (wholesale) during fixture teardown.
    """
    current_environ = os.environ.copy()
    yield os.environ
    os.environ = current_environ