[issue21750] mock_open data is visible only once for the life of the class

2015-07-25 Thread Robert Collins
Changes by Robert Collins : -- resolution: -> fixed stage: needs patch -> resolved status: open -> closed ___ Python tracker ___ ___

[issue21750] mock_open data is visible only once for the life of the class

2015-07-23 Thread Roundup Robot
Roundup Robot added the comment: New changeset 83e28ee348bf by Robert Collins in branch '3.4': Issue #21750: Further fixup to be styled like other mock APIs. https://hg.python.org/cpython/rev/83e28ee348bf New changeset b30fc1de006c by Robert Collins in branch '3.5': Issue #21750: Further fixup t

[issue21750] mock_open data is visible only once for the life of the class

2015-07-23 Thread Robert Collins
Robert Collins added the comment: Discussed with Michael Foord; we're going to go with the -2 patch - the new behaviour. -- ___ Python tracker ___ __

[issue21750] mock_open data is visible only once for the life of the class

2015-07-23 Thread Robert Collins
Robert Collins added the comment: @Paul So the problem is that its never been a high fidelity thing in that sense In that: 3.3 -> read() is a constant for the thing opened from the mock 3.4 -> read() works once and only once across all opened files from the mock 3.5 today -> read() works on

[issue21750] mock_open data is visible only once for the life of the class

2015-07-23 Thread Michael Foord
Michael Foord added the comment: So the problem with the testing-cabal issue 280 is *really* a problem with decorators - the decorator is applied at method creation time and mock_open is only called once rather than once *per call*. Better would be to use mock.patch as a context manager inside

[issue21750] mock_open data is visible only once for the life of the class

2015-07-22 Thread Paul Koning
Paul Koning added the comment: Section 26.7.7 of the library manual describes mock_open with the words: A helper function to create a mock to replace the use of open. It works for open called directly or used as a context manager. which implies that it works just like open. Given that it does

[issue21750] mock_open data is visible only once for the life of the class

2015-07-22 Thread Robert Collins
Robert Collins added the comment: Which part of the docs specifically? -- ___ Python tracker ___ ___ Python-bugs-list mailing list Uns

[issue21750] mock_open data is visible only once for the life of the class

2015-07-22 Thread Paul Koning
Paul Koning added the comment: I suppose. And it certainly is much better than the original behavior. But if this is the approach chosen, it should be clearly called out in the documentation, because the current wording suggests the 1.1.4 behavior, not the one you recommended. --

[issue21750] mock_open data is visible only once for the life of the class

2015-07-21 Thread Robert Collins
Robert Collins added the comment: So the 1.1.4 behaviour matches that of a VFS most closely. But, see the earlier messages, it does do only and precisely because it breaks regular mock idioms. Thus I think we're better off with the new patch, which addresses the issue with reuse of the mocks i

[issue21750] mock_open data is visible only once for the life of the class

2015-07-21 Thread Paul Koning
Paul Koning added the comment: So if I understand right, it seems to me the 3.5/mock 1.1.4 behavior is correct. mock_open(read_data="f") acts like a file that contains f, and m() acts like an open() of that file. So if I call open once, I should read the f, then EOF. If I open twice, then e

[issue21750] mock_open data is visible only once for the life of the class

2015-07-21 Thread Robert Collins
Robert Collins added the comment: @pkoning in Python3.3 == mock 1.0.1, >>> m = mock_open(read_data='f') >>> m().read() 'f' >>> m().read() 'f' >>> x = m() >>> x.read() 'f' >>> x.read() 'f' >>> x = m() >>> y = m() >>> x.read() 'f' >>> y.read() 'f' in 3.4 == mock 1.1.{0,1,2,3}, and 1.2.0 >>> m = m

[issue21750] mock_open data is visible only once for the life of the class

2015-07-21 Thread Paul Koning
Paul Koning added the comment: Sure, you can use a vfs. That's true for a lot of mock functions; the benefit of mock, including mock_open, is that it provides an easier and better packaged way. The behavior expected is "be like a file". So in that last example, if you open it twice, you've

[issue21750] mock_open data is visible only once for the life of the class

2015-07-21 Thread Robert Collins
Robert Collins added the comment: But - its worth discussing. Perhaps we should roll this all back, and just say 'use a vfs layer for tests like this'. The problem in doing that, is that the @patch def test_foo... use case is actually pretty common IME, and this conflicts with the @patch ... A

[issue21750] mock_open data is visible only once for the life of the class

2015-07-21 Thread Robert Collins
Robert Collins added the comment: Fixup patch. I've tested this with the reported failures and they all work. -- Added file: http://bugs.python.org/file39967/issue-21750-2.patch ___ Python tracker _

[issue21750] mock_open data is visible only once for the life of the class

2015-07-17 Thread Robert Collins
Robert Collins added the comment: The fix for this uncovered more testing / scenarios that folk use mock_open for that were not accounted for. I'm reverting it from mock, and am going to roll-forward for Python: I should have a fix in a day or two and we can fix it more completely then. http

[issue21750] mock_open data is visible only once for the life of the class

2015-07-17 Thread Roundup Robot
Roundup Robot added the comment: New changeset 41d55ac50dea by Robert Collins in branch '3.4': Issue #21750: mock_open.read_data can now be read from each instance, as it https://hg.python.org/cpython/rev/41d55ac50dea New changeset 0da764c58322 by Robert Collins in branch '3.5': Issue #21750: mo

[issue21750] mock_open data is visible only once for the life of the class

2015-07-17 Thread Robert Collins
Robert Collins added the comment: Ok, so - good to commit to 3.4 and up? -- ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue21750] mock_open data is visible only once for the life of the class

2015-07-17 Thread Berker Peksag
Berker Peksag added the comment: > There are already explicit tests for that Great, then the test is fine :) Thanks for writing the patch. -- ___ Python tracker ___

[issue21750] mock_open data is visible only once for the life of the class

2015-07-17 Thread Robert Collins
Robert Collins added the comment: There are already explicit tests for that, do you want another one? -- ___ Python tracker ___ ___ Py

[issue21750] mock_open data is visible only once for the life of the class

2015-07-16 Thread Berker Peksag
Berker Peksag added the comment: LGTM. A minor comment: +def test_mock_open_reuse_issue_21750(self): We can also add an assert to check the data is actually "data" (e.g. assertEqual(f1.read(), 'data')). -- stage: patch review -> commit review

[issue21750] mock_open data is visible only once for the life of the class

2015-07-16 Thread Berker Peksag
Changes by Berker Peksag : -- stage: -> patch review ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://m

[issue21750] mock_open data is visible only once for the life of the class

2015-07-14 Thread Robert Collins
Changes by Robert Collins : -- keywords: +patch Added file: http://bugs.python.org/file39928/issue-21750.patch ___ Python tracker ___

[issue21750] mock_open data is visible only once for the life of the class

2015-07-14 Thread Robert Collins
Robert Collins added the comment: I think its worth noting that both the original mock_open and the new one are entirely broken for mocking access to multiple files. But, the breakage was not deliberate, and as the mock-280 example shows, folk subclassing a test suite will be surprisingly brok

[issue21750] mock_open data is visible only once for the life of the class

2015-07-14 Thread Robert Collins
Changes by Robert Collins : -- assignee: -> rbcollins versions: +Python 3.5, Python 3.6 ___ Python tracker ___ ___ Python-bugs-list m

[issue21750] mock_open data is visible only once for the life of the class

2015-07-14 Thread Robert Collins
Robert Collins added the comment: This is a regression in 3.5 vs 3.3 I think. It would have worked with the initial mock import. https://github.com/testing-cabal/mock/issues/280 Minimal reproducer case attached (With commentted out bits to switch out the mock for the rolling backport etc). -

[issue21750] mock_open data is visible only once for the life of the class

2015-03-06 Thread Berker Peksag
Changes by Berker Peksag : -- nosy: +berker.peksag ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue21750] mock_open data is visible only once for the life of the class

2015-03-06 Thread Mac Ryan
Mac Ryan added the comment: I'm a bit lost in the interface of this bugtracker, so I apologise if I am writing in the wrong spot, anyhow... I just wanted to signal that this bug breaks the inter-operability between mock (external library) and unittest.mock, breaking tests that have been origin

[issue21750] mock_open data is visible only once for the life of the class

2014-06-13 Thread Ned Deily
Changes by Ned Deily : -- nosy: +michael.foord ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyt

[issue21750] mock_open data is visible only once for the life of the class

2014-06-13 Thread Paul Koning
New submission from Paul Koning: The read_data iterator that supplies bits of read data when asked from unittest.mock.mock_open is a class attribute. The result is that, if you instantiate the class multiple times, that iterator is shared. This isn't documented and it seems counterintuitive.