-
Notifications
You must be signed in to change notification settings - Fork 20
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
Break the unit test suite's reliance on os.environ #10
Conversation
Some unit tests won't run unless os.environ is set. Mock out the required environment variables so that the unit tests pass.
|
||
|
||
@pytest.fixture | ||
def docker_env_vars(monkeypatch): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Some unit tests won't run unless os.environ is set. Mock out the
required environment variables so that the unit tests pass.