-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
plugin: unittestrelated to the unittest integration builtin pluginrelated to the unittest integration builtin plugintopic: marksrelated to marks, either the general marks or builtinrelated to marks, either the general marks or builtintype: bugproblem that needs to be addressedproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previouslyindicates a problem that was introduced in a release which was working previously
Description
Thanks for submitting an issue!
Here's a quick checklist in what to include:
- Include a detailed description of the bug or suggestion
@pytest.mark.usefixtures()
on test cases in classes that inherit from unittest.TestCase and unittest2.TestCase no longer works. The fixtures are completely ignored.
Given your README.rst says Can run unittest (or trial), nose test suites out of the box;
, I'm assuming this is an appropriate bug to file.
-
pip list
of the virtual environment you are using
In both venvs, I installed pytest and unittest2. The remaining packages are just dependencies
python 3.6.3
Owens-MacBook-Pro:bug owen$ pip list
Package Version
-------------- -------
atomicwrites 1.1.5
attrs 18.1.0
linecache2 1.0.0
more-itertools 4.1.0
pip 10.0.1
pluggy 0.6.0
py 1.5.3
pytest 3.6.0
setuptools 39.2.0
six 1.11.0
traceback2 1.4.0
unittest2 1.1.0
wheel 0.31.1
python 2.7.10
Owens-MacBook-Pro:bug owen$ pip list
Package Version
-------------- -------
atomicwrites 1.1.5
attrs 18.1.0
funcsigs 1.0.2
linecache2 1.0.0
more-itertools 4.1.0
pip 10.0.1
pluggy 0.6.0
py 1.5.3
pytest 3.6.0
setuptools 39.2.0
six 1.11.0
traceback2 1.4.0
unittest2 1.1.0
wheel 0.31.1
-
pytest and operating system versions
pytest 3.6.0
macOS High Sierra 10.13.4 -
Minimal example if possible
conftest.py
import pytest
@pytest.fixture(scope='function')
def fixture1():
print("in fixture1")
yield
@pytest.fixture(scope='function')
def fixture2():
print("in fixture2")
yield
tests.py
import pytest
# import unittest
# import unittest2
# class Tests(unittest.TestCase):
# class Tests(unittest2.TestCase):
class Tests(object):
@pytest.mark.usefixtures("fixture1")
def test_one(self):
print("inside test_one")
@pytest.mark.usefixtures("fixture1", "fixture2")
def test_two(self):
print("inside test_two")
Results identical between python 2.7.10 and 3.6.3:
using class Tests(object)
Owens-MacBook-Pro:bug owen$ pytest -s tests.py
=============================== test session starts ===============================
platform darwin -- Python 2.7.10, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
rootdir: /Users/owen/repos/sandbox/bug, inifile:
collected 2 items
tests.py in fixture1
inside test_one
.in fixture1
in fixture2
inside test_two
.
============================ 2 passed in 0.02 seconds =============================
using class Tests(unittest.TestCase)
Owens-MacBook-Pro:bug owen$ pytest -s tests.py
=============================== test session starts ===============================
platform darwin -- Python 2.7.10, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
rootdir: /Users/owen/repos/sandbox/bug, inifile:
collected 2 items
tests.py inside test_one
.inside test_two
.
============================ 2 passed in 0.01 seconds =============================
Notice in fixture1
and in fixture2
is not printed
using class Tests(unittest2.TestCase)
Owens-MacBook-Pro:bug owen$ pytest -s tests.py
=============================== test session starts ===============================
platform darwin -- Python 2.7.10, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
rootdir: /Users/owen/repos/sandbox/bug, inifile:
collected 2 items
tests.py inside test_one
.inside test_two
.
============================ 2 passed in 0.04 seconds =============================
Notice in fixture1
and in fixture2
is not printed
I also installed pytest 3.5.1 instead of 3.6.0 to show it was working before using unittest2:
Owens-MacBook-Pro:bug owen$ pytest -s tests.py
=============================== test session starts ===============================
platform darwin -- Python 2.7.10, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /Users/owen/repos/sandbox/bug, inifile:
collected 2 items
tests.py running fixture1
inside test_one
.running fixture1
running fixture2
inside test_two
.
============================ 2 passed in 0.02 seconds =============================
Metadata
Metadata
Assignees
Labels
plugin: unittestrelated to the unittest integration builtin pluginrelated to the unittest integration builtin plugintopic: marksrelated to marks, either the general marks or builtinrelated to marks, either the general marks or builtintype: bugproblem that needs to be addressedproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previouslyindicates a problem that was introduced in a release which was working previously