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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import pytest


@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.

"""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

monkeypatch.setenv('TRANSPLANT_URL', 'http://autoland.test')
2 changes: 2 additions & 0 deletions tests/test_phabricator_client.py
Original file line number Diff line number Diff line change
@@ -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.



def test_get_revision_with_200_response():
phab = PhabricatorClient(api_key='api-key')
2 changes: 2 additions & 0 deletions tests/test_revisions.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
from tests.canned_responses.phabricator.repos import *
from tests.canned_responses.lando_api.revisions import *

pytestmark = pytest.mark.usefixtures('docker_env_vars')


def test_get_revision_with_no_parents(client):
with requests_mock.mock() as m: