beanbaginc / kgb

Python function spy support for unit tests
MIT License
48 stars 5 forks source link

Pytest failing on python 3.10 #8

Closed jonathanspw closed 1 year ago

jonathanspw commented 1 year ago

It might impact other versions as well.

___________________________________________________________________________________ FunctionSpyTests.test_call_original_with_unbound_method_no_instance ____________________________________________________________________________________
TypeError: The first argument to add_one.call_original() must be an instance of kgb_.tests.test_function_spy.AdderObject, since this is an unbound method.

During handling of the above exception, another exception occurred:

self = <kgb_.tests.test_function_spy.FunctionSpyTests testMethod=test_call_original_with_unbound_method_no_instance>

>   ???
E   AssertionError: "The\ first\ argument\ to\ add_one\.call_original\(\)\ must\ be\ an\ instance\ of\ kgb\.tests\.test_function_spy\.AdderObject,\ since\ this\ is\ an\ unbound\ method\." does not match "The first argument to add_one.call_original() must be an instance of kgb_.tests.test_function_spy.AdderObject, since this is an unbound method."

/home/jonathan/python-kgb/kgb-release-7.0/kgb/tests/test_function_spy.py:1207: AssertionError
------------------------------------------------------------------------------------------------------------ Captured log call -------------------------------------------------------------------------------------------------------------
WARNING  kgb:signature.py:556 Determined the owner of <function AdderObject.add_one at 0x7f3568173a30> to be <class 'kgb_.tests.test_function_spy.AdderObject'>, but it may be wrong. Please pass owner= to spy_on() to set a specific owner.
chipx86 commented 1 year ago

Thanks for the report!

Very strange. What version of Python 3.10 are you using?

We have this tested with 3.10.0, 3.10.1, and 3.10.5, and all tests are passing.

jonathanspw commented 1 year ago

I'm trying to build native packages for Fedora to go in the official repos.

[jonathan@jon-fedora-build kgb-release-7.0]$ python3 --version
Python 3.10.5

I can recreate the issue "on demand" outside of our package building envinroment. On my local Fedora 36 workstation using Python 3.10.5 cited above: https://pastebin.com/ZnneWtBP

I've also recreated the error in Python 3.9.10. I've not tested 3.6-3.8.

chipx86 commented 1 year ago

The stated error message seems to differ because the latter has kgb_ instead kgb. Is this some artifact of the packaging, or some patch applied? It's not part of our codebase.

jonathanspw commented 1 year ago

I had to move the kgb dir out of the way so it would run tests against the installed module and not the one in the local dir.

chipx86 commented 1 year ago

Ah, ok. So that's probably the issue, if it has a new name, because the error message is going to be based on the module path of the thing being spied on, and we want to assert it's what we expect. If you need to move it as part of any automation, I'd recommend making a new parent directory and putting kgb inside of it, keeping the name intact.

jonathanspw commented 1 year ago

Thanks for the info on what it was doing exactly. I found a workaround on our end so we can keep the test in place.