You are setting the wrong mock: mock_tmp
is not the context manager, but instead returns a context manager. Replace your setup line with:
mock_tmp.return_value.__enter__.return_value.name = mytmpname
and your test will work.
More Related Contents:
- How can I mock requests and the response?
- Trying to mock datetime.date.today(), but not working
- python mocking raw input in unittests
- How to mock an import
- How do I mock an open used in a with statement (using the Mock framework in Python)?
- Can I patch a Python decorator before it wraps a function?
- Why python mock patch doesn’t work?
- Python mock multiple return values
- Python Mock object with method called multiple times
- How can one mock/stub python module like urllib
- Mocking a class: Mock() or patch()?
- Mock attributes in Python mock?
- How can I mock user input (from “input” in 3.x, or “raw_input” in 2.x) for a unit test?
- How to monkeypatch python’s datetime.datetime.now with py.test?
- Mocking boto3 S3 client method Python
- What is your favorite Python mocking library? [closed]
- Mock Python’s built in print function
- How to test or mock “if __name__ == ‘__main__'” contents
- Using mock patch to mock an instance method
- Mocking Functions Using Python Mock
- Python mock Patch os.environ and return value
- python mock – patching a method without obstructing implementation
- Customizing unittest.mock.mock_open for iteration
- Unit testing a python app that uses the requests library
- python: mock a module
- Django: How to create a model dynamically just for testing
- Can I “fake” a package (or at least a module) in python for testing purposes?
- How to mock a readonly property with mock?
- Is there a way to ordinate numbers in a list?
- A non-blocking read on a subprocess.PIPE in Python