-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Dependencies between xunit-style setups and the other fixtures #5949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
you could make a pytest plugin that raises errors when xunit style setup is used |
I thought about this. |
Example of implementation of a such plugin (based on attributes of Produces output:
|
@stanislavlevin that looks like a good start, if you use the results of the makeitem hooks and use item.warn, you can have to the point warnings for the classes/modules that use xunit style setups to be on the safe side, please take into account that setup_foo fixtures are allowed anf replace xunit with fixture style |
@RonnyPfannschmidt, thank you very much for the clues. For example, import unittest
class TestClass:
def test_1(self):
pass
class TestCase(unittest.TestCase):
def test_method1(self):
pass @pytest.hookimpl(hookwrapper=True)
def pytest_pycollect_makeitem(collector, name, obj):
outcome = yield
res = outcome.get_result()
if res is not None:
if isinstance(res, list):
for n in res:
print(n.name)
else:
print(type(res)) Run only one test class
I thought that the result produced by this hook will be filtered by collection (I mean only Updated version of plugin: import sys
import pytest
forb_mod_scope = [
'setup_module',
'setup_function',
'teardown_module',
'teardown_function',
]
forb_cls_scope = [
'setup_class',
'setup_method',
'teardown_class',
'teardown_method',
]
def pytest_collection_finish(session):
unit_test = sys.modules.get('unittest', None)
unit_test_cls = getattr(unit_test, "TestCase", None)
for item in session.items:
cls = getattr(item, 'cls', None)
subclassed = False
if unit_test_cls is not None and cls is not None:
subclassed = issubclass(cls, unit_test_cls)
if subclassed:
item.warn(pytest.PytestWarning("unittest is deprecated"))
continue
def xunit_depr_warn(item, attr, names):
for n in names:
obj = getattr(item, attr, None)
method = getattr(obj, n, None)
fixtured = hasattr(method, '__pytest_wrapped__')
if method is not None and not fixtured:
item.warn(pytest.PytestWarning("xunit style is deprecated\n"))
xunit_depr_warn(item, 'module', forb_mod_scope)
xunit_depr_warn(item, 'cls', forb_cls_scope) |
#4091 introduced a nice feature employed xunit-style setups and unittest definitions as internal fixtures.
But unfortunately, it looks like there is no way to make a strict order of fixture setup as It made in case of regular ones. Yes, sure, setup*/teardown* have
their own fixture names, but they are internal, for example:
I couldn't rely on them since they are not documented and could be different from release to release.
The second problem that even if I drop xunit/unittest setups I can't forbid their usage by Pytest means.
The text was updated successfully, but these errors were encountered: