reset standard os env after each test

This commit is contained in:
David Lord 2018-01-10 13:53:45 -08:00
parent f2cf4d0449
commit 8bdf820e9b
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 43 additions and 18 deletions

View file

@ -23,9 +23,11 @@ from _pytest.monkeypatch import notset
from click.testing import CliRunner
from flask import Flask, current_app
from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, dotenv, \
find_best_app, get_version, load_dotenv, locate_app, prepare_import, \
from flask.cli import (
AppGroup, FlaskGroup, NoAppException, ScriptInfo, dotenv,
find_best_app, get_version, load_dotenv, locate_app, prepare_import,
with_appcontext
)
cwd = os.getcwd()
test_path = os.path.abspath(os.path.join(
@ -33,19 +35,6 @@ test_path = os.path.abspath(os.path.join(
))
@pytest.fixture(autouse=True)
def manage_os_environ(monkeypatch):
# can't use monkeypatch.delitem since we don't want to restore a value
os.environ.pop('FLASK_APP', None)
os.environ.pop('FLASK_DEBUG', None)
# use monkeypatch internals to force-delete environ keys
monkeypatch._setitem.extend((
(os.environ, 'FLASK_APP', notset),
(os.environ, 'FLASK_DEBUG', notset),
(os.environ, 'FLASK_RUN_FROM_CLI', notset),
))
@pytest.fixture
def runner():
return CliRunner()