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

Break the unit test suite's reliance on os.environ #10

Merged

Conversation

mars-f
Copy link
Contributor

@mars-f mars-f commented Jun 15, 2017

Some unit tests won't run unless os.environ is set. Mock out the
required environment variables so that the unit tests pass.

Some unit tests won't run unless os.environ is set.  Mock out the
required environment variables so that the unit tests pass.
@mars-f mars-f requested a review from purelogiq June 15, 2017 19:24


@pytest.fixture
def docker_env_vars(monkeypatch):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a file tests/utils.py which contains utility and setup functions that every test uses. Can you move this function to that file? Unless there is a purpose for this file in the near future. I just want to avoid having a bunch of test setup across different files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind! I see that conftest.py is a common pattern with pytest.

@@ -16,6 +16,8 @@
from tests.canned_responses.phabricator.repos import *
from tests.canned_responses.phabricator.errors import *

pytestmark = pytest.mark.usefixtures('docker_env_vars')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that if you also move this to test/utils.py then we won't have to add it at the top of every test file, every test file can just import the utils file as they already do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the specifics above, but, otherwise is there a better way to have this be done automatically for every test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing the fixture won't apply it - you need to include a fixture in the module's pytestmark to apply it to every test in a file.

@pytest.fixture
def docker_env_vars(monkeypatch):
"""Monkeypatch environment variables that we'd get running under docker."""
monkeypatch.setenv('PHABRICATOR_URL', 'http://phabricator.test')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to change the phab url, can you also go through and update all the canned responses to use this URL? Right now they use the default mozphab.aws URL which came from the original docker-compose.yml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@purelogiq purelogiq merged commit b58a084 into mozilla-conduit:master Jun 20, 2017
@mars-f mars-f deleted the break-test-reliance-on-os-environ branch June 20, 2017 14:22
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 this pull request may close these issues.

2 participants