New issue 616: (2.6.3) Conftest is ran, but fixtures not brought in.
https://bitbucket.org/hpk42/pytest/issue/616/263-conftest-is-ran-but-fixtures-not
Chris B:
Framework:
```
#!
.drivers\
.logs\
.plugins\
.sessions\
.testbeds\
.tests\
.utils\
.conftest.py
```
All files in the directories (except for the logs) are python files. There is
no extra conftest.py file within any of these directories.
When using a command line start, there is a user defined option to bring in a
testbed module. This is defined in the conftest.py file along with how to
import it into a test (through fixtures).
These fixtures would be seen by a test in the tests directory **prior to
2.6.3**.
When trying to do the same command line with 2.6.3, an error is shown:
```
#!
=================================== ERRORS ====================================
_____________ ERROR at setup of <testname> ______________
file <testpath>\<testname>.py, line <line #>
def test_test ( self , tb_testbed , request ):
fixture 'tb_testbed' not found
available fixtures: <user defined fixutres in the test>, pytestconfig,
recwarn, monkeypatch, capfd, capsys, tmpdir
use 'py.test --fixtures [testpath]' for help on them.
<testpath>\<testname>.py:<line #>
===================== 1 xfailed, 1 error in 0.05 seconds ======================
```
If the test is moved to the top level directory, then the fixtures are seen.
If the line:
```
#!python
from conftest import tb_testbed, tb_name
```
is added to the test, then the fixtures are brought in as well.
Is this a bug or a previous bug that was fixed?
Thank you very much for your time.
conftest.py:
```
#!python
import pytest
import telnetlib
import time
import datetime
import os
import sys
import logging
import importlib
import re
from time import gmtime, strftime, localtime
full_path = os.path.realpath(__file__)
tempTopLevelDir, file = os.path.split(os.path.realpath(__file__))
# add specific dirs to the sys.path so you can import any modules created there.
tempDriversDir = os.path.join(tempTopLevelDir,'drivers')
tempPluginsDir = os.path.join(tempTopLevelDir,'plugins')
tempSessionsDir = os.path.join(tempTopLevelDir,'sessions')
tempTestbedsDir = os.path.join(tempTopLevelDir,'testbeds')
tempUtilsDir = os.path.join(tempTopLevelDir,'utils')
sys.path.extend( [tempDriversDir, tempPluginsDir, tempSessionsDir,
tempTestbedsDir, tempUtilsDir] )
#allow for testbed option
def pytest_addoption(parser):
parser.addoption("--testbed", action = "store", help = "Specify testbed for
test run")
#get testbed option
@pytest.fixture(scope="session")
def tb_name(request):
request.config.tb_name = request.config.getoption("--testbed")
return request.config.tb_name
@pytest.fixture(scope="module")
def tb_testbed(request, tb_name):
#get testbed information for test
assert tb_name != None, "--testbed command line option required"
try:
testbed = importlib.import_module('testbeds.' + tb_name)
return testbed
except:
raise Exception("testbed not found!")
```
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit