Skip to content
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

Fix: avoiding issue with PytestUnraisableExceptionWarning #1458

Merged
merged 4 commits into from Mar 14, 2022

Conversation

advance512
Copy link
Contributor

@advance512 advance512 commented Mar 9, 2021

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Does travis tests pass with this change (enable it first in your forked repo and wait for the travis build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Description of change

Fix: avoiding issue with PytestUnraisableExceptionWarning that is raised because of __del__() calling self.close() in Redis class, as the self.connection attribute was not set due to early failure in the Redis() constructor.

Example, without this fix:

redis = redis.StrictRedis(**connectionInfo)

in a test for redlock-py, you get this warning due to an unraisable exception:

=============================== warnings summary ===============================
tests/test_redlock.py::TestRedlock::test_bad_connection_info
  /home/user/redlock-py/.venv/lib/python3.8/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in: <function Redis.__del__ at 0x7fd05a194820>
  
  Traceback (most recent call last):
    File "/home/user/redlock-py/.venv/lib/python3.8/site-packages/redis/client.py", line 885, in __del__
      self.close()
    File "/home/user/redlock-py/.venv/lib/python3.8/site-packages/redis/client.py", line 888, in close
      conn = self.connection
  AttributeError: 'Redis' object has no attribute 'connection'
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================= 6 passed, 1 warning in 0.65s =========================

…sed because of __del__() calling self.close() in Redis class, as the self.connection attribute was not set due to early failure in the Redis() constructor. Example: calling redis.StrictRedis(**connectionInfo) in a constructor, with connectionInfo={'hog':'cat'}
@github-actions
Copy link
Contributor

This pull request is marked stale. It will be closed in 30 days if it is not updated.

@github-actions github-actions bot added the Stale label Mar 10, 2022
@chayim
Copy link
Contributor

chayim commented Mar 14, 2022

@dvora-h can you check if this is still valid?

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2022

Codecov Report

Merging #1458 (f4fff1c) into master (8d949a3) will increase coverage by 0.00%.
The diff coverage is 50.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1458   +/-   ##
=======================================
  Coverage   92.17%   92.17%           
=======================================
  Files         100      100           
  Lines       21024    21026    +2     
=======================================
+ Hits        19378    19381    +3     
+ Misses       1646     1645    -1     
Impacted Files Coverage Δ
redis/client.py 89.30% <50.00%> (-0.09%) ⬇️
tests/test_cluster.py 98.42% <0.00%> (+0.12%) ⬆️

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 8d949a3...f4fff1c. Read the comment docs.

Copy link
Collaborator

@dvora-h dvora-h left a comment

Choose a reason for hiding this comment

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

More than a year ... but yes, it's still valid and we can merge it

@dvora-h dvora-h added the maintenance Maintenance (CI, Releases, etc) label Mar 14, 2022
@dvora-h dvora-h merged commit a081173 into redis:master Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance (CI, Releases, etc) Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants