Hi All,

> Stuart Bishop wrote:
> The tearDown method could reset the mock easily enough.

If only it were that simple :-)

To patch imports, the harness was actually providing a context that you
could use the wrap the imports at the top of your test module. That solved
the immediate issue of executing imports without errors, but it created a
very complex situation when you went to figure out which references to
cleanup or update when you wanted to reset mocks. You also weren't able to
clean them up in tearDown, or even tearDownClass, because you had to handle
the situation where you had multiple test classes in a module.

One workaround is to do your imports inside of the setUp for a test. That
didn't feel like the correct way to do things in a library meant for
general use, where I'd prefer to stick to things that don't make Guido sad.
I wouldn't necessarily object to the technique if it came up in a code
review for a specific charm, though :-)

~ PeteVG

On Thu, Sep 1, 2016 at 4:48 AM Stuart Bishop <stuart.bis...@canonical.com>
wrote:

> On 30 August 2016 at 23:02, Pete Vander Giessen <
> pete.vandergies...@canonical.com> wrote:
>
> The problems with the harness: patching sys.modules leads to a catch-22:
>> if we don't leave the mocks in place, we still get import errors when using
>> the mock library's mock.patch method, but if we do leave them in place,
>> tests that set properties on them can end up interfering with each other.
>> There are workarounds, but they're not intuitive, and they don't generate
>> friendly error messages when they fail. We felt it best to leave the
>> harness behind, and provide some advice on more straightforward things that
>> you can do to work around the import errors. Thus the PR referenced above.
>>
>
> The tearDown method could reset the mock easily enough. I didn't need to
> do that in the simple case I had (a single layer), but it should solve the
> test isolation issue you have.
>
>
>
> --
> Stuart Bishop <stuart.bis...@canonical.com>
>
-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju

Reply via email to