Hi All,
I'm faced with very strange issue with runtest_call hook.
I've create plugin with such hook and it's working good unless you have the
following code in the test case:
assert env.switch[1].type == "real"
If you change at least on sign in this assertion (e.g. != "real" or ==
"unreal") the issue cannot be reproduced and hook is performed correctly.
Could anybody explain me what is going with this test case?
Thank you in advance!
-Anton
Here the code:
$ tree
.
├── conftest.py
├── pytest_fake.py
└── test_temp.py
*1. conftest.py*
#! /usr/bin/env python
pytest_plugins = ["pytest_fake", ]
def pytest_runtest_call(item):
print "\nconftest runtest call"
def pytest_runtest_teardown(item, nextitem):
print "\nconftest runtest teardown"
*2. pytest_fake.py*
#!/usr/bin/env python
import pytest
def pytest_addoption(parser):
group = parser.getgroup("fake", "plugin fake")
group.addoption("--fake", action="store_true", dest="fake",
default=False,
help="Enable fake plugin. %default by default.")
def pytest_configure(config):
if config.option.fake:
config.pluginmanager.register(Fake(config.option), "_fake")
def pytest_unconfigure(config):
fake = getattr(config, "_fake", None)
if fake:
del config._fake
config.pluginmanager.unregister(fake)
class Fake(object):
def __init__(self, opts):
pass
@pytest.mark.trylast
def pytest_runtest_call(self, item):
print "runtest_call - OK"
@pytest.mark.tryfirst
def pytest_runtest_teardown(self, item, nextitem):
print "runtest_teardown"
*3. test_temp.py*
#! /usr/bin/env python
class A:
pass
class B:
def __init__(self):
self.switch = {}
self.switch[1] = A()
self.switch[1].type = "unreal"
class TestTemp(object):
def test_tmp_01(self):
var = B()
assert var.switch[1].type == "real"
def test_tmp_02(self):
env1 = B()
assert env1.switch[1].type != "real"
*Execution log:*
I'm expecting that message "runtest_call - OK" will appear before the first
case.
$ py.test -s -v --fake test_temp.py
================================================= test session starts
=================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4 -- /usr/bin/python
collected 2 items
test_temp.py:13: TestTemp.test_tmp_01
conftest runtest call
FAILEDruntest_teardown
conftest runtest teardown
test_temp.py:17: TestTemp.test_tmp_02
conftest runtest call
runtest_call - OK
PASSEDruntest_teardown
conftest runtest teardown
====================================================== FAILURES
=======================================================
________________________________________________ TestTemp.test_tmp_01
_________________________________________________
self = <test_temp.TestTemp object at 0x15e6f90>
def test_tmp_01(self):
var = B()
> assert var.switch[1].type == "real"
E assert 'unreal' == 'real'
E - unreal
E ? --
E + real
self = <test_temp.TestTemp object at 0x15e6f90>
var = <test_temp.B instance at 0x16293f8>
test_temp.py:15: AssertionError
=============================================== slowest test durations
================================================
0.00s call test_temp.py::TestTemp::test_tmp_01
0.00s setup test_temp.py::TestTemp::test_tmp_01
0.00s teardown test_temp.py::TestTemp::test_tmp_01
0.00s call test_temp.py::TestTemp::test_tmp_02
0.00s setup test_temp.py::TestTemp::test_tmp_02
0.00s teardown test_temp.py::TestTemp::test_tmp_02
========================================= 1 failed, 1 passed in 0.02
seconds ==========================================
_______________________________________________
Pytest-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pytest-dev