Skip to content

Monkeypatch + Session Scope #1872

@mlcamilli

Description

@mlcamilli

From the documentation

# content of conftest.py
@pytest.fixture(scope='session', autouse=True)
def enable_debugging(monkeypatch):
    monkeypatch.setenv("DEBUGGING_VERBOSITY", "4")

This auto-use fixture will set the DEBUGGING_VERBOSITY environment variable for the entire test session.

Note that the ability to use a monkeypatch fixture from a session-scoped fixture was added in pytest-3.0.

However when running pytest 3.0.1

============================================================ 
test session starts =============================================================
platform linux -- Python 3.5.2, pytest-3.0.1, py-1.4.31, pluggy-0.3.1
rootdir: /code, inifile: 
plugins: flask-0.10.0
collected 51 items 

This is the error thrown

ScopeMismatch: You tried to access the 'function' scoped fixture 'monkeypatch' with a 'session' scoped request object, involved factories
tests/conftest.py:6:  def local_es(monkeypatch)
../usr/local/lib/python3.5/site-packages/_pytest/monkeypatch.py:12:  def monkeypatch(request)

This is the fixture

   @pytest.fixture(scope="session", autouse=True)
   def local_es(monkeypatch):                                                                                                                                                                                                                                                                                                
       monkeypatch.setenv('ELASTICSEARCH_HOST', 'ES') 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions