Skip to content

Bugfix: monkeypatch.delattr handles class descriptors#4537

Merged
nicoddemus merged 3 commits into
pytest-dev:masterfrom
chdsbd:master
Jan 16, 2019
Merged

Bugfix: monkeypatch.delattr handles class descriptors#4537
nicoddemus merged 3 commits into
pytest-dev:masterfrom
chdsbd:master

Conversation

@chdsbd

@chdsbd chdsbd commented Dec 12, 2018

Copy link
Copy Markdown
Contributor

Correct monkeypatch.delattr to match the correct behavior of monkeypatch.setattr when changing class descriptors.

Issue: #4536

Correct monkeypatch.delattr to match the correct behavior of
monkeypatch.setattr when changing class descriptors

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution @chdsbd!

@asottile asottile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@codecov

codecov Bot commented Dec 12, 2018

Copy link
Copy Markdown

Codecov Report

Merging #4537 into master will decrease coverage by 0.05%.
The diff coverage is 91.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4537      +/-   ##
==========================================
- Coverage   95.92%   95.87%   -0.06%     
==========================================
  Files         111      111              
  Lines       25119    25141      +22     
  Branches     2449     2450       +1     
==========================================
+ Hits        24096    24104       +8     
- Misses        723      731       +8     
- Partials      300      306       +6
Flag Coverage Δ
#docs 29.13% <0%> (-0.86%) ⬇️
#doctesting 29.13% <0%> (-0.86%) ⬇️
#linting 29.13% <0%> (-0.86%) ⬇️
#linux 95.74% <91.3%> (-0.02%) ⬇️
#nobyte 92.05% <91.3%> (-0.64%) ⬇️
#numpy 41.77% <0%> (-51.71%) ⬇️
#pexpect 41.77% <0%> (-0.07%) ⬇️
#py27 93.92% <91.3%> (-0.14%) ⬇️
#py34 92.05% <91.3%> (-0.07%) ⬇️
#py35 92.07% <91.3%> (-0.07%) ⬇️
#py36 92.05% <91.3%> (-0.11%) ⬇️
#py37 94.1% <91.3%> (-0.01%) ⬇️
#trial 41.77% <0%> (-51.71%) ⬇️
#windows 91.73% <91.3%> (-2.41%) ⬇️
#xdist 93.95% <91.3%> (-0.04%) ⬇️
Impacted Files Coverage Δ
src/_pytest/monkeypatch.py 94.03% <100%> (+0.16%) ⬆️
testing/test_monkeypatch.py 98.91% <88.88%> (-0.7%) ⬇️
testing/test_tmpdir.py 97.15% <0%> (-1.71%) ⬇️
src/_pytest/pathlib.py 89.56% <0%> (-1.1%) ⬇️
src/_pytest/cacheprovider.py 96.15% <0%> (-0.97%) ⬇️
src/_pytest/capture.py 93.66% <0%> (-0.46%) ⬇️
src/_pytest/pytester.py 87.01% <0%> (-0.43%) ⬇️

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 6af674a...7a600ea. Read the comment docs.

@codecov

codecov Bot commented Dec 12, 2018

Copy link
Copy Markdown

Codecov Report

Merging #4537 into master will decrease coverage by 0.01%.
The diff coverage is 91.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4537      +/-   ##
==========================================
- Coverage   95.92%   95.91%   -0.02%     
==========================================
  Files         111      111              
  Lines       25119    25141      +22     
  Branches     2449     2450       +1     
==========================================
+ Hits        24096    24114      +18     
- Misses        723      726       +3     
- Partials      300      301       +1
Flag Coverage Δ
#docs 30.05% <0%> (+0.06%) ⬆️
#doctesting 30.05% <0%> (+0.06%) ⬆️
#linting 30.05% <0%> (+0.06%) ⬆️
#linux 95.74% <91.3%> (-0.02%) ⬇️
#nobyte 92.67% <91.3%> (-0.01%) ⬇️
#numpy 93.45% <91.3%> (-0.04%) ⬇️
#pexpect 41.77% <0%> (-0.07%) ⬇️
#py27 94.05% <91.3%> (-0.01%) ⬇️
#py34 92.17% <91.3%> (+0.06%) ⬆️
#py35 92.19% <91.3%> (+0.06%) ⬆️
#py36 92.21% <91.3%> (+0.06%) ⬆️
#py37 94.11% <91.3%> (ø) ⬆️
#trial 93.45% <91.3%> (-0.04%) ⬇️
#windows 94.13% <91.3%> (-0.01%) ⬇️
#xdist 93.98% <91.3%> (-0.01%) ⬇️
Impacted Files Coverage Δ
src/_pytest/monkeypatch.py 94.03% <100%> (+0.16%) ⬆️
testing/test_monkeypatch.py 98.91% <88.88%> (-0.7%) ⬇️
src/_pytest/capture.py 93.66% <0%> (-0.46%) ⬇️

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 6af674a...9b3be87. Read the comment docs.

raise AttributeError(name)
else:
self._setattr.append((target, name, getattr(target, name, notset)))
oldval = getattr(target, name, notset)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this inadvertently triggers misbehaviours

a) ignores the MRO
b) always goes the normal path, even for classes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm confused how this is different from the current behavior of setattr. I believe this works the exact same as before, except in the case of the class, where we match the behavior of setattr.

Is there an example you can provide to correct my misunderstanding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I understand what you be regarding b. I mimicked the implementation for monkeypatch.setattr. I can update both of them if you want to use an if-else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@RonnyPfannschmidt any more comments here?

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

its good now, thanks for the ping

@nicoddemus nicoddemus merged commit 1a04e89 into pytest-dev:master Jan 16, 2019
@nicoddemus

Copy link
Copy Markdown
Member

Thanks again @chdsbd!

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.

5 participants