Show HN: Forbidden Fruit – Patch built-in Python objects
clarete.github.com
Show HN: Forbidden Fruit – Patch built-in Python objects
1–10 of 16 posts
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#2Man, having this as a context manager (maybe with the help of contextlib) would be great, because context managers are great.
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#3Man, having this as a context manager (maybe with the help of contextlib) would be great, because context managers are great.
That's the idea. Everything to make testing easier! :)
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#4What's the use case?
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#5What's the use case?
I have two main use cases in my mind right now.
1) Making it easier to write tools for testing python code, like sure[0] and freezegun[1]
2) Prototyping new features for python without touching the C code.
[0] http://github.com/gabrielfalcao/sure -- where forbiddenfruit started) [1] http://github.com/spulec/freezegun
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#6What's the use case?
It's a dirty hack - therefore, fun.
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#7If you are doing this for testing, it's already a feature of pytest: http://pytest.org/latest/monkeypatch.html
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#8What are the license implications of using GPLv3 code as part of a test suite?
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#9While it is a cool project, I hope I never have to work on a project that use this. I hate when people overwrite built-ins, but that might just be me.
Re: Show HN: Forbidden Fruit – Patch built-in Python objects
#10If you are doing this for testing, it's already a feature of pytest: http://pytest.org/latest/monkeypatch.html
I might be wrong, but I don't think that it's actually possible to mock built-in objects (written in C, not in python) using pytest.
A very quick test would be trying to do something like this:
>>> monkeypatch(str, "blah", "bleh") >>> assert str.blah == "bleh"
I tried it here with no success though.