plone / plone.app.testing

Testing tools for Plone-the-application
http://pypi.python.org/pypi/plone.app.testing
2 stars 7 forks source link

MockMailHostLayer isolation issues #62

Closed ale-rt closed 4 years ago

ale-rt commented 4 years ago

I have this file (see bottom of the issue) with two tests that use the MOCK_MAILHOST_FIXTURE as stated in the documentation:

If now I run:

./bin/test -t TestCase1 -t TestCase2

or

./bin/test -t TestCase2 -t TestCase1

The test_mailhost2 is failing because the portal mailhost is not the fake one.

Note that this is fixed here https://github.com/plone/plone.app.testing/commit/0882636c708f68072c442766d3f6af38bd4b2b08 or by replacing MOCK_MAILHOST_FIXTURE with:

from plone.app.testing.layers import MockMailHostLayer
...
    bases=(MY_FIXTURE1, MockMailHostLayer()), name="My:Integration1"
...

Either I am using the fixture improperly or there is an issue.

If the latter I am not sure what is the best way to fix it. Should we:

  1. keep the documentation like it is ad setup/teardown the mock mailhost at every test as proposed in https://github.com/plone/plone.app.testing/commit/0882636c708f68072c442766d3f6af38bd4b2b08
  2. change the documentation and suggest to use a fresh instance of MockMailHostLayer() for every layer
  3. whatever you suggest

Minimal file that can be used to reproduce the issue.

# coding=utf-8
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer
from plone.app.testing.layers import MOCK_MAILHOST_FIXTURE
from plone.app.testing.utils import MockMailHost
from unittest import TestCase

class MyFixture1(PloneSandboxLayer):

    defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

class MyFixture2(PloneSandboxLayer):

    defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

MY_FIXTURE1 = MyFixture1()
MY_FIXTURE2 = MyFixture2()

MY_TESTING1 = IntegrationTesting(
    bases=(MY_FIXTURE1, MOCK_MAILHOST_FIXTURE), name="My:Integration1"
)
MY_TESTING2 = IntegrationTesting(
    bases=(MY_FIXTURE2, MOCK_MAILHOST_FIXTURE), name="My:Integration2"
)

class TestCase1(TestCase):
    layer = MY_TESTING1

    def test_mailhost1(self):
        self.assertIsInstance(self.layer["portal"].MailHost, MockMailHost)

class TestCase2(TestCase):
    layer = MY_TESTING2

    def test_mailhost2(self):
        self.assertIsInstance(self.layer["portal"].MailHost, MockMailHost)