<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import textwrap

import py

import pytest
from _pytest.config import PytestPluginManager
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_USAGEERROR


@pytest.fixture(scope="module", params=["global", "inpackage"])
def basedir(request, tmpdir_factory):
    tmpdir = tmpdir_factory.mktemp("basedir", numbered=True)
    tmpdir.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
    tmpdir.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
    if request.param == "inpackage":
        tmpdir.ensure("adir/__init__.py")
        tmpdir.ensure("adir/b/__init__.py")
    return tmpdir


def ConftestWithSetinitial(path):
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [path])
    return conftest


def conftest_setinitial(conftest, args, confcutdir=None):
    class Namespace(object):
        def __init__(self):
            self.file_or_dir = args
            self.confcutdir = str(confcutdir)
            self.noconftest = False
            self.pyargs = False

    conftest._set_initial_conftests(Namespace())


class TestConftestValueAccessGlobal(object):
    def test_basic_init(self, basedir):
        conftest = PytestPluginManager()
        p = basedir.join("adir")
        assert conftest._rget_with_confmod("a", p)[1] == 1

    def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
        conftest = PytestPluginManager()<commit_msg>Fix test_conftest when run via pytest-randomly<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import textwrap

import py

import pytest
from _pytest.config import PytestPluginManager
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_USAGEERROR
from _pytest.pytester import SysModulesSnapshot
from _pytest.pytester import SysPathsSnapshot


def ConftestWithSetinitial(path):
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [path])
    return conftest


def conftest_setinitial(conftest, args, confcutdir=None):
    class Namespace(object):
        def __init__(self):
            self.file_or_dir = args
            self.confcutdir = str(confcutdir)
            self.noconftest = False
            self.pyargs = False

    conftest._set_initial_conftests(Namespace())


class TestConftestValueAccessGlobal(object):
    @pytest.fixture(scope="module", params=["global", "inpackage"])
    def basedir(self, request, tmpdir_factory):
        tmpdir = tmpdir_factory.mktemp("basedir", numbered=True)
        tmpdir.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
        tmpdir.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
        if request.param == "inpackage":
            tmpdir.ensure("adir/__init__.py")
            tmpdir.ensure("adir/b/__init__.py")

        yield tmpdir

    @pytest.fixture(autouse=True)
    def restore(self):
        """Restore sys.modules to prevent ConftestImportFailure when run randomly."""
        snapmods = SysModulesSnapshot()
        snappath = SysPathsSnapshot()
        yield
        snapmods.restore()
        snappath.restore()

    def test_basic_init(self, basedir):
        conftest = PytestPluginManager()
        p = basedir.join("adir")
        assert conftest._rget_with_confmod("a", p)[1] == 1

    def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
        conftest = PytestPluginManager()
{'fraction_non_alphanumeric': 0.09684560044272275, 'fraction_numerical': 0.00387382401770891, 'mean_word_length': 3.7944297082228116, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3710301', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1171, 'n_words': 229}