|
10 | 10 | import os |
11 | 11 | import pathlib |
12 | 12 | import sys |
13 | | -import types |
14 | 13 |
|
15 | 14 | import pytest |
16 | 15 |
|
@@ -333,72 +332,6 @@ def pytest_configure(): |
333 | 332 | _setup_django() |
334 | 333 |
|
335 | 334 |
|
336 | | -def _classmethod_is_defined_at_leaf(cls, method_name): |
337 | | - super_method = None |
338 | | - |
339 | | - for base_cls in cls.__mro__[1:]: # pragma: no branch |
340 | | - super_method = base_cls.__dict__.get(method_name) |
341 | | - if super_method is not None: |
342 | | - break |
343 | | - |
344 | | - assert super_method is not None, ( |
345 | | - "%s could not be found in base classes" % method_name |
346 | | - ) |
347 | | - |
348 | | - method = getattr(cls, method_name) |
349 | | - |
350 | | - try: |
351 | | - f = method.__func__ |
352 | | - except AttributeError: |
353 | | - pytest.fail("{}.{} should be a classmethod".format(cls, method_name)) |
354 | | - return f is not super_method.__func__ |
355 | | - |
356 | | - |
357 | | -_disabled_classmethods = {} |
358 | | - |
359 | | - |
360 | | -def _disable_class_methods(cls): |
361 | | - if cls in _disabled_classmethods: |
362 | | - return |
363 | | - |
364 | | - _disabled_classmethods[cls] = ( |
365 | | - # Get the classmethod object (not the resulting bound method), |
366 | | - # otherwise inheritance will be broken when restoring. |
367 | | - cls.__dict__.get("setUpClass"), |
368 | | - _classmethod_is_defined_at_leaf(cls, "setUpClass"), |
369 | | - cls.__dict__.get("tearDownClass"), |
370 | | - _classmethod_is_defined_at_leaf(cls, "tearDownClass"), |
371 | | - ) |
372 | | - |
373 | | - cls.setUpClass = types.MethodType(lambda cls: None, cls) |
374 | | - cls.tearDownClass = types.MethodType(lambda cls: None, cls) |
375 | | - |
376 | | - |
377 | | -def _restore_class_methods(cls): |
378 | | - ( |
379 | | - setUpClass, |
380 | | - restore_setUpClass, |
381 | | - tearDownClass, |
382 | | - restore_tearDownClass, |
383 | | - ) = _disabled_classmethods.pop(cls) |
384 | | - |
385 | | - try: |
386 | | - del cls.setUpClass |
387 | | - except AttributeError: |
388 | | - raise |
389 | | - |
390 | | - try: |
391 | | - del cls.tearDownClass |
392 | | - except AttributeError: |
393 | | - pass |
394 | | - |
395 | | - if restore_setUpClass: |
396 | | - cls.setUpClass = setUpClass |
397 | | - |
398 | | - if restore_tearDownClass: |
399 | | - cls.tearDownClass = tearDownClass |
400 | | - |
401 | | - |
402 | 335 | @pytest.hookimpl(tryfirst=True) |
403 | 336 | def pytest_collection_modifyitems(items): |
404 | 337 | # If Django is not configured we don't need to bother |
|
0 commit comments