[issue11664] Add patch method to unittest.TestCase

2020-02-10 Thread Guido van Rossum
Guido van Rossum added the comment: Given the two recent -1 responses let's close this. -- nosy: +gvanrossum resolution: -> wont fix stage: -> resolved status: open -> closed ___ Python tracker

[issue11664] Add patch method to unittest.TestCase

2019-11-27 Thread Brett Cannon
Change by Brett Cannon : -- nosy: -brett.cannon ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue11664] Add patch method to unittest.TestCase

2019-09-11 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I concur with Raymond here. Since mock is also part of stdlib and this issue predates mock being merged to stdlib. I think adding it to unittest sort of expands the unittest API being just an alias to mock.patch. mock.patch is used in lot of

[issue11664] Add patch method to unittest.TestCase

2019-09-10 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 I think mocking should be kept orthogonal to the unittest module. A person is free to use mocking with different testing tools like py.test or nose. Likewise, they are free to use a different mocking/patching tool than our standard library mock.

[issue11664] Add patch method to unittest.TestCase

2019-09-10 Thread Tahia K
Change by Tahia K : -- nosy: +ta1hia ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue11664] Add patch method to unittest.TestCase

2016-10-04 Thread Mariatta Wijaya
Changes by Mariatta Wijaya : -- nosy: +Mariatta ___ Python tracker ___ ___

[issue11664] Add patch method to unittest.TestCase

2016-09-19 Thread Christian Heimes
Changes by Christian Heimes : -- versions: +Python 3.7 -Python 3.5 ___ Python tracker ___

[issue11664] Add patch method to unittest.TestCase

2014-11-07 Thread Robert Collins
Robert Collins added the comment: +1 on a plain function or context manager. w.r.t. addCleanUp taking a context manager, that could be interesting - perhaps we'd want a thing where you pass it the context manager, it __enter__'s the manager and then calls addCleanUp for you. --

[issue11664] Add patch method to unittest.TestCase

2014-10-12 Thread Julian Berman
Julian Berman added the comment: My opinion is already here re: patch vs patch.object, so I won't repeat it, but @Michael, if you really want .patch, are you open to adding .patch_object as well? (Regardless, thanks for working on this Julien.) --

[issue11664] Add patch method to unittest.TestCase

2014-10-12 Thread Michael Foord
Michael Foord added the comment: The patch (including lazy import) looks good, and the test looks ok too. I still think that patch should be the default instead of patch.object - although I wouldn't object to a second method (name?) if there was significant demand. --

[issue11664] Add patch method to unittest.TestCase

2014-10-12 Thread Robert Collins
Robert Collins added the comment: FWIW I'd really like to be reducing the TestCase API not extending it - particularly since there are lots of good convenient ways of doing this already (not least mock.patch/mock.patch.object). So I'm -0.5 on adding this, as I don't see it adding value. That

[issue11664] Add patch method to unittest.TestCase

2014-10-12 Thread Ezio Melotti
Ezio Melotti added the comment: I'm -0.5 on this as well, and agree that we should try to keep the TestCase API small. On one hand, a patch method available without extra imports would be handy, and having this as a generic function/method in unittest seems more natural to me than having it

[issue11664] Add patch method to unittest.TestCase

2014-10-12 Thread Martin Panter
Martin Panter added the comment: [padding to avoid UTF-8 error with bug tracker] See also Issue 22374, where an equivalent of “patch.object” is suggested as an example context manager for the “contextlib” documentation. If we added a plain function or context manager rather than a new

[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Julien Pagès
Julien Pagès added the comment: Hi all, I would like to contribute to Python and I'm interested in working on this. I have few questions (I hope you don't mind that I ask here): - is this issue still open and needed ? - if yes, do I have to work from 3.3 branch, as stated in the issue

[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Antoine Pitrou
Antoine Pitrou added the comment: Hi Julien and welcome, - is this issue still open and needed ? Yes and perhaps. I have no opinion on whether it is necessary, but other people seem to think it's useful. - if yes, do I have to work from 3.3 branch, as stated in the issue Versions field,

[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Antoine Pitrou
Changes by Antoine Pitrou pit...@free.fr: -- assignee: michael.foord - versions: +Python 3.5 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___

[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Julien Pagès
Julien Pagès added the comment: Thanks Antoine for the link, and the quick answer; It seems that it is a sensible subject, adding or not this method, and what it should do. I wrote the patch anyway, but I must confess that somewhere it feels strange to me to add such a method in TestCase

[issue11664] Add patch method to unittest.TestCase

2014-08-05 Thread Martin Panter
Changes by Martin Panter vadmium...@gmail.com: -- nosy: +vadmium ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___ Python-bugs-list

[issue11664] Add patch method to unittest.TestCase

2013-03-27 Thread Michael Foord
Michael Foord added the comment: Yes this is still relevant and needs doing (and is easy). The implementation should be similar to: def patch(self, *args, **kwargs): # lazy import from unittest.mock import patch p = patch(*args, **kwargs) result = p.start()

[issue11664] Add patch method to unittest.TestCase

2013-03-26 Thread Brett Cannon
Brett Cannon added the comment: So, what's the status of this? Move it forward or close this? -- status: open - pending ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___

[issue11664] Add patch method to unittest.TestCase

2012-09-19 Thread Michael Foord
Michael Foord added the comment: It maybe that patch.object is a more natural interface to the small sample of people commenting here, in which case great - that's what it's there for. However in common usage patch is used around two orders of magnitude more. I've seen large codebases with

[issue11664] Add patch method to unittest.TestCase

2012-09-19 Thread Éric Araujo
Éric Araujo added the comment: A data point: at work I follow Pyramid testing guidelines which tell you not to import code under test at module level, but in your test functions, so that if you have an error your tests do start and you see the error under the test method. This means that I

[issue11664] Add patch method to unittest.TestCase

2012-09-18 Thread Julian Berman
Julian Berman added the comment: It's slightly less confusing -- Where do I patch is the question that will never go away, and the fact that you don't have the `sys` module imported is a small hint that you should be doing patch(mymodule.sys, path) not patch(sys.path). Also, the fact that

[issue11664] Add patch method to unittest.TestCase

2012-09-18 Thread Michael Foord
Michael Foord added the comment: Well, people vote with their code and find mock.patch vastly more useful than patch.object... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___

[issue11664] Add patch method to unittest.TestCase

2012-09-18 Thread R. David Murray
R. David Murray added the comment: I actually agree with Julian here. I much prefer patch.object and do my best to avoid mock.patch. support.patch is also equivalent to patch.object and not patch. That doesn't change the fact that other people prefer mock.patch, of course. I think

[issue11664] Add patch method to unittest.TestCase

2012-09-18 Thread Julian Berman
Julian Berman added the comment: With all due respect, your response pretty much ignored mine completely. That's OK, I've agreed with you that patch seems more common. I'll point you additionally though to the fact that Éric's original post also used patch.object's semantics, as does

[issue11664] Add patch method to unittest.TestCase

2012-09-18 Thread Chris Jerdonek
Chris Jerdonek added the comment: What about patch_object()? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___ Python-bugs-list

[issue11664] Add patch method to unittest.TestCase

2012-09-18 Thread Ezio Melotti
Ezio Melotti added the comment: IMHO a setattr-like API seems the obvious choice here, so that's what I would expect. I haven't used mock, so I wasn't familiar with mock.patch, but after skimming through the mock docs a bit I think I have to agree with Julian and RDM. In addition, I'm not

[issue11664] Add patch method to unittest.TestCase

2012-09-17 Thread Michael Foord
Michael Foord added the comment: Why would mock.patch.object be the appropriate one to add to TestCase? patch.object is used orders of magnitude less than patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664

[issue11664] Add patch method to unittest.TestCase

2012-09-15 Thread Julian Berman
Julian Berman added the comment: It's kind of unfortunate that `mock.patch` is called `mock.patch`. I was thinking about this a bit more yesterday, and `mock.patch.object` is the one that I think would be most appropriate to put on `TestCase`, and the best name for it is probably `patch`, but

[issue11664] Add patch method to unittest.TestCase

2012-09-04 Thread Julian Berman
Changes by Julian Berman julian+python@grayvines.com: -- nosy: +Julian ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___

[issue11664] Add patch method to unittest.TestCase

2012-08-23 Thread moijes12
Changes by moijes12 moije...@gmail.com: -- nosy: -moijes12 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___ Python-bugs-list mailing

[issue11664] Add patch method to unittest.TestCase

2012-08-23 Thread Chris Jerdonek
Changes by Chris Jerdonek chris.jerdo...@gmail.com: -- nosy: +cjerdonek ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___

[issue11664] Add patch method to unittest.TestCase

2012-07-02 Thread moijes12
Changes by moijes12 moije...@gmail.com: -- nosy: +moijes12 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___ Python-bugs-list mailing

[issue11664] Add patch method to unittest.TestCase

2012-03-12 Thread Michael Foord
Michael Foord mich...@voidspace.org.uk added the comment: mock is being added to Python 3.3 as unittest.mock - so a helper TestCase.patch should delegate to unittest.mock.patch. -- ___ Python tracker rep...@bugs.python.org

[issue11664] Add patch method to unittest.TestCase

2011-05-26 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: There’s also test.support.swap_attr... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___

[issue11664] Add patch method to unittest.TestCase

2011-03-29 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: A similar function already exists: test.support.patch -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___

[issue11664] Add patch method to unittest.TestCase

2011-03-29 Thread Michael Foord
Michael Foord mich...@voidspace.org.uk added the comment: Right, I helped with the writing of that at PyCon. The patch method would look very similar. test.support.patch is not something we want to make public (in that location). -- ___ Python

[issue11664] Add patch method to unittest.TestCase

2011-03-26 Thread Pablo Mouzo
Pablo Mouzo pablomo...@gmail.com added the comment: I'm attaching a draft patch for patch. Éric, is this patch implementing patch as you expected? This patch is not finished because there are many cases where patch can leave patched objects if it fails to unpatch. -- keywords: +patch

[issue11664] Add patch method to unittest.TestCase

2011-03-26 Thread Michael Foord
Michael Foord mich...@voidspace.org.uk added the comment: I'd like to ponder this a bit. Note that the patch is incorrect - fetching the attribute should not be done with getattr (this will trigger descriptors instead of fetching the underlying member) and should not be reset unconditionally

[issue11664] Add patch method to unittest.TestCase

2011-03-25 Thread Daniel Urban
Changes by Daniel Urban urban.dani...@gmail.com: -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___ Python-bugs-list

[issue11664] Add patch method to unittest.TestCase

2011-03-25 Thread Brett Cannon
Changes by Brett Cannon br...@python.org: -- nosy: +brett.cannon ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___ ___ Python-bugs-list

[issue11664] Add patch method to unittest.TestCase

2011-03-24 Thread Éric Araujo
New submission from Éric Araujo mer...@netwok.org: A common thing to do in setUp or test* methods is to replace some module attribute with something else, either to mock an object calling an external resource or to test platform-specific behavior (for example, changing os.name before calling

[issue11664] Add patch method to unittest.TestCase

2011-03-24 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: Typo s/self.path/self.patch/ I forgot to mention the rationale for this method: factor out common code to make sure the cleanup is not forgotten. Also kill debates about addCleanup vs. tearDown vs. try/finally. --

[issue11664] Add patch method to unittest.TestCase

2011-03-24 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: Needless to say the name is open: patch, replace, settempvalue, what have you. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11664 ___