question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why is pytest_sessionstart in conftest.py causing 'Fixtures are not meant to be called directly' error?

See original GitHub issue

Hi,

Can anyone explain why the pytest_sessionstart fixture in conftest.py is causing an error relating to Fixtures are not meant to be called directly?

I have searched the root directory and there are no further references to pytest_sessionstart so the fixture is not being called anywhere else within the project.

I have installed the project source code from requirements.txt file using pip install -r requirements.txt

The conftest.py file is listed below. If I uncomment the pytest_sessionstart fixture tests run!

I am using pytest 4.1.1 on OSX High Sierra 10.13.6.

import locale
import logging
import pytest

from pyramid_core.testing import FileServerFactory
from pyramid_core.testing.factories import TestEnvironment

def pytest_configure(config):
    TestEnvironment(config)

def pytest_addoption(parser):
    parser.addini("file.server.path", "file server")

@pytest.fixture(scope='session')
def docker_compose_files(pytestconfig):
    config = FileServerFactory.get_config(pytestconfig)
    return config.validated_files

@pytest.fixture(autouse=True, scope='session')
def pytest_sessionstart( ):
    locale.setlocale(locale.LC_TIME, '')
    logging.basicConfig(level=logging.INFO,
        format='%(asctime)s    %(levelname)s    %(module)s::%(funcName)s line %(lineno)s %(message)s',
        datefmt='%x:%X')

    logging.info('datetime locale set to {}'.format(locale.getlocale(category=locale.LC_TIME)))
    logging.info('logging configured')

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
RonnyPfannschmidtcommented, Jan 14, 2019

a pytest hook is never a fixture

so by marking the pytest_sessionstart hook as fixture instead of a pytest.hookimpl() you literally shoot your own foot

0reactions
dcs3sppcommented, Jan 14, 2019

Oops, ok apologies…

Cheers @RonnyPfannschmidt and @nicoddemus. That got me up and running 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found