[issue44503] Hide __enter__ calls in mock_open

2021-06-24 Thread Pierre Ossman


New submission from Pierre Ossman :

I'd like to write this test case:

  with patch('builtins.open') as pyopen:
mock_open(pyopen, read_data="foo")
run()
pyopen.assert_has_calls([call("filename", "wt"),
 call().write("gazonk"),
 call().close()])

and I shouldn't have to care if the code is written like this:

  def run():
f = open("filename", "wt")
try:
  write("gazonk")
finally:
  f.close()

or like this:

  def run():
with open("filename", "wt") as f:
  write("gazonk")

--
components: Library (Lib)
messages: 396469
nosy: CendioOssman
priority: normal
severity: normal
status: open
title: Hide __enter__ calls in mock_open
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44503] Hide __enter__ calls in mock_open

2021-06-24 Thread Pierre Ossman


Pierre Ossman  added the comment:

Also see Issue44185 for __exit__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44503] Hide __enter__ calls in mock_open

2021-06-26 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy: +michael.foord

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com