Skip to content
New issue

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

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

Already on GitHub? # to your account

Look at os.environ before early_config #199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ def pytest_load_initial_conftests(early_config, parser, args):

# Configure DJANGO_SETTINGS_MODULE
ds = (options.ds or
early_config.getini(SETTINGS_MODULE_ENV) or
os.environ.get(SETTINGS_MODULE_ENV))
os.environ.get(SETTINGS_MODULE_ENV) or
early_config.getini(SETTINGS_MODULE_ENV))

# Configure DJANGO_CONFIGURATION
dc = (options.dc or
early_config.getini(CONFIGURATION_ENV) or
os.environ.get(CONFIGURATION_ENV))
os.environ.get(CONFIGURATION_ENV) or
early_config.getini(CONFIGURATION_ENV))

if ds:
os.environ[SETTINGS_MODULE_ENV] = ds
Expand Down
12 changes: 6 additions & 6 deletions tests/test_django_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ def test_settings():


def test_dc_ini(testdir, monkeypatch):
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'DO_NOT_USE')
monkeypatch.setenv('DJANGO_CONFIGURATION', 'DO_NOT_USE')
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.settings_env')
monkeypatch.setenv('DJANGO_CONFIGURATION', 'MySettings')

testdir.makeini("""
[pytest]
DJANGO_SETTINGS_MODULE = tpkg.settings_ini
DJANGO_CONFIGURATION = MySettings
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
DJANGO_CONFIGURATION = DO_NOT_USE_ini
""")
pkg = testdir.mkpydir('tpkg')
settings = pkg.join('settings_ini.py')
settings = pkg.join('settings_env.py')
settings.write(BARE_SETTINGS)
testdir.makepyfile("""
import os

def test_ds():
assert os.environ['DJANGO_SETTINGS_MODULE'] == 'tpkg.settings_ini'
assert os.environ['DJANGO_SETTINGS_MODULE'] == 'tpkg.settings_env'
assert os.environ['DJANGO_CONFIGURATION'] == 'MySettings'
""")
result = testdir.runpytest()
Expand Down
5 changes: 3 additions & 2 deletions tests/test_django_settings_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ def test_settings():


def test_ds_ini(testdir, monkeypatch):
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'DO_NOT_USE')
"DSM env should override ini."
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.settings_ini')
testdir.makeini("""\
[pytest]
DJANGO_SETTINGS_MODULE = tpkg.settings_ini
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
""")
pkg = testdir.mkpydir('tpkg')
settings = pkg.join('settings_ini.py')
Expand Down