hRobert12 / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Allow change properties of objects or modules #197

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm trying to change a settings property, only for a case.

Example:

1. My objects uses a django.conf.setting.ITEM_PER_PAGE property
2. In my test I want to change this value avoiding side effects on other tests.

For now i'm changing the value by hand and backing the before value on 
afterEach. But i'm afraid of forgetting the afterEach one day, so i propose to 
have some signature like this:

with mock.patch.properties(settings, ITEM_PER_PAGE=2):
    #my test here

What do you think?

Original issue reported on code.google.com by timo...@gmail.com on 28 Jan 2013 at 7:33

GoogleCodeExporter commented 8 years ago
How would this be different to:

with mock.patch.object(settings, 'ITEM_PER_PAGE', 2):
    # ...

Or:

with mock.patch.multiple(settings, ITEM_PER_PAGE=2):
   # ...

?

Original comment by fuzzyman on 29 Jan 2013 at 10:42

GoogleCodeExporter commented 8 years ago

Original comment by fuzzyman on 14 Nov 2013 at 11:12