"""A pytest plugin for using pyfakefs as a fixture

When pyfakefs is installed, the "fs" fixture becomes available.

:Usage:

def my_fakefs_test(fs):
    fs.create_file('/var/data/xx1.txt')
    assert os.path.exists('/var/data/xx1.txt')
"""
import py
import pytest
from pyfakefs.fake_filesystem_unittest import Patcher

Patcher.SKIPMODULES.add(py)  # Ignore pytest components when faking filesystem


@pytest.fixture
def fs(request):
    """ Fake filesystem. """
    patcher = Patcher()
    patcher.setUp()
    request.addfinalizer(patcher.tearDown)
    return patcher.fs

"""A pytest plugin for using pyfakefs as a fixture

When pyfakefs is installed, the "fs" fixture becomes available.

:Usage:

def my_fakefs_test(fs):
    fs.create_file('/var/data/xx1.txt')
    assert os.path.exists('/var/data/xx1.txt')
"""
import linecache

import py
import pytest
from pyfakefs.fake_filesystem_unittest import Patcher

Patcher.SKIPMODULES.add(py)  # Ignore pytest components when faking filesystem
Patcher.SKIPMODULES.add(linecache)  # Seems to be used by pytest internally


@pytest.fixture
def fs(request):
    """ Fake filesystem. """
    patcher = Patcher()
    patcher.setUp()
    request.addfinalizer(patcher.tearDown)
    return patcher.fs

Add linecache module to skipped modules for pytest plugin
Add linecache module to skipped modules for pytest plugin

- see #381
- fixes the problem under Python 3, but not under Python 2
