From 1110808a9d39d4b808aef724c861a2e1a38d2a69 Mon Sep 17 00:00:00 2001
From: Devtools Arcadia <arcadia-devtools@yandex-team.ru>
Date: Mon, 7 Feb 2022 18:08:42 +0300
Subject: intermediate changes ref:cde9a383711a11544ce7e107a78147fb96cc4029

---
 contrib/python/pytest/py3/_pytest/nose.py | 38 +++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 contrib/python/pytest/py3/_pytest/nose.py

(limited to 'contrib/python/pytest/py3/_pytest/nose.py')

diff --git a/contrib/python/pytest/py3/_pytest/nose.py b/contrib/python/pytest/py3/_pytest/nose.py
new file mode 100644
index 0000000000..d6f3c2b224
--- /dev/null
+++ b/contrib/python/pytest/py3/_pytest/nose.py
@@ -0,0 +1,38 @@
+""" run test suites written for nose. """
+from _pytest import python
+from _pytest import unittest
+from _pytest.config import hookimpl
+
+
+@hookimpl(trylast=True)
+def pytest_runtest_setup(item):
+    if is_potential_nosetest(item):
+        if not call_optional(item.obj, "setup"):
+            # call module level setup if there is no object level one
+            call_optional(item.parent.obj, "setup")
+        # XXX this implies we only call teardown when setup worked
+        item.session._setupstate.addfinalizer((lambda: teardown_nose(item)), item)
+
+
+def teardown_nose(item):
+    if is_potential_nosetest(item):
+        if not call_optional(item.obj, "teardown"):
+            call_optional(item.parent.obj, "teardown")
+
+
+def is_potential_nosetest(item):
+    # extra check needed since we do not do nose style setup/teardown
+    # on direct unittest style classes
+    return isinstance(item, python.Function) and not isinstance(
+        item, unittest.TestCaseFunction
+    )
+
+
+def call_optional(obj, name):
+    method = getattr(obj, name, None)
+    isfixture = hasattr(method, "_pytestfixturefunction")
+    if method is not None and not isfixture and callable(method):
+        # If there's any problems allow the exception to raise rather than
+        # silently ignoring them
+        method()
+        return True
-- 
cgit v1.2.3