Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockMailHostLayer isolation issues #62

Closed
ale-rt opened this issue Dec 12, 2019 · 0 comments · Fixed by #64
Closed

MockMailHostLayer isolation issues #62

ale-rt opened this issue Dec 12, 2019 · 0 comments · Fixed by #64

Comments

@ale-rt
Copy link
Member

ale-rt commented Dec 12, 2019

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 0882636 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 0882636
  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)
ale-rt added a commit that referenced this issue Feb 4, 2020
Fix a test isolation issue that was preventing the MOCK_MAILHOST_FIXTURE
to be used in multiple testcases (Fixes #61),

Properly configure the mail sender setting the appropriate registry
records (Fixes #62),

Adds test coverage.
ale-rt added a commit that referenced this issue Feb 5, 2020
Fix a test isolation issue that was preventing the MOCK_MAILHOST_FIXTURE
to be used in multiple testcases (Fixes #61),

Properly configure the mail sender setting the appropriate registry
records (Fixes #62),

Adds test coverage.
ale-rt added a commit that referenced this issue Feb 5, 2020
Fix a test isolation issue that was preventing the MOCK_MAILHOST_FIXTURE
to be used in multiple testcases (Fixes #61),

Properly configure the mail sender setting the appropriate registry
records (Fixes #62),

Adds test coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant