V
V
Valery Semenov2013-01-24 15:17:28
Python
Valery Semenov, 2013-01-24 15:17:28

How to simplify the design?

Something tells me that such a design can be simplified.
It can't be that python won't have a prettier notation for this.
(here I hang mocks on class methods)

with mock.patch(
            "mf_system.models.mf_article.MfSystemArticle._relate_with_text",
             side_effect=TestException()
        ):
            with mock.patch(
                "mf_system.models.mf_article.MfSystemArticle.load_file",
                return_value='test_file_name'
            ):
                with mock.patch(
                    "tools.load_file.delete_file", return_value=1
                ) as mock_file:
                    try:
                           ......

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Akulovich, 2013-01-24
@Ravall

from contextlib import nested

with nested(mock.patch(...), mock.patch(...), ...):
  ...
here
A with python 2.7 is generally just like this:
with mock.patch(...), mock.patch(...), ...:
    ... 

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question