Skip to content

Fix another unittest regression (#624) #625

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

Closed
wants to merge 2 commits into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jul 4, 2018

Fixes #624.

@codecov-io
Copy link

codecov-io commented Jul 4, 2018

Codecov Report

Merging #625 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #625      +/-   ##
==========================================
+ Coverage   92.33%   92.36%   +0.02%     
==========================================
  Files          32       32              
  Lines        1710     1715       +5     
  Branches      142      142              
==========================================
+ Hits         1579     1584       +5     
  Misses         94       94              
  Partials       37       37
Flag Coverage Δ
#dj110 84.48% <100%> (+0.04%) ⬆️
#dj111 86.58% <100%> (+0.03%) ⬆️
#dj18 85.3% <100%> (+0.04%) ⬆️
#dj19 84.37% <100%> (+0.04%) ⬆️
#dj20 84.78% <100%> (+0.04%) ⬆️
#dj21 84.78% <100%> (+0.04%) ⬆️
#djmaster ?
#mysql_innodb 84.78% <100%> (+0.04%) ⬆️
#mysql_myisam 84.72% <100%> (+0.04%) ⬆️
#postgres 88.16% <100%> (+0.03%) ⬆️
#py27 89.73% <100%> (+0.03%) ⬆️
#py34 84.37% <100%> (+0.04%) ⬆️
#py35 84.48% <100%> (+0.04%) ⬆️
#py36 85.24% <100%> (+0.04%) ⬆️
#sqlite 86.58% <100%> (+0.03%) ⬆️
#sqlite_file 84.37% <100%> (+0.04%) ⬆️
Impacted Files Coverage Δ
tests/test_unittest.py 100% <100%> (ø) ⬆️
pytest_django/plugin.py 86% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1bc024...4acd913. Read the comment docs.

@blueyed
Copy link
Contributor Author

blueyed commented Jul 4, 2018

Ping @kleptog (via #597).

@blueyed blueyed changed the title [WIP] #624: fix another unittest regression Fix another unittest regression (#624) Jul 4, 2018
@blueyed blueyed requested a review from adamchainz July 4, 2018 19:25
Copy link
Member

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a more correct fix, updating _classmethod_is_defined_at_leaf to check in __dict__ like the other code

diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py
index 3a82b62..5d4f323 100644
--- a/pytest_django/plugin.py
+++ b/pytest_django/plugin.py
@@ -268,8 +268,8 @@ def _classmethod_is_defined_at_leaf(cls, method_name):
     super_method = None
 
     for base_cls in cls.__mro__[1:]:  # pragma: no branch
-        if hasattr(base_cls, method_name):
-            super_method = getattr(base_cls, method_name)
+        super_method = base_cls.__dict__.get(method_name)
+        if super_method is not None:
             break
 
     assert super_method is not None, (
@@ -295,16 +295,12 @@ def _disable_class_methods(cls):
     if cls in _disabled_classmethods:
         return
 
-    # Get the classmethod object (not the resulting bound method),
-    # otherwise inheritence will be broken when restoring.
-    # But fall back to bound method in case it is None in __dict__.
-    setUpClass = cls.__dict__.get('setUpClass', cls.setUpClass)
-    tearDownClass = cls.__dict__.get('tearDownClass', cls.tearDownClass)
-
     _disabled_classmethods[cls] = (
-        setUpClass,
+        # Get the classmethod object (not the resulting bound method),
+        # otherwise inheritance will be broken when restoring.
+        cls.__dict__.get('setUpClass'),
         _classmethod_is_defined_at_leaf(cls, 'setUpClass'),
-        tearDownClass,
+        cls.__dict__.get('tearDownClass'),
         _classmethod_is_defined_at_leaf(cls, 'tearDownClass'),
     )

@blueyed
Copy link
Contributor Author

blueyed commented Jul 20, 2018

Thanks, @adamchainz!
Pushed your fixup.

Copy link
Member

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@blueyed blueyed closed this Jul 26, 2018
@blueyed blueyed reopened this Jul 26, 2018
@blueyed blueyed closed this in be42484 Jul 26, 2018
beyondgeeks pushed a commit to beyondgeeks/django-pytest that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants