diff --git a/tests/conftest.py b/tests/conftest.py index 9217d8d3..aa3782cf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,23 +66,23 @@ def limit_loader(request, monkeypatch): @pytest.fixture -def apps_tmpdir(tmpdir, monkeypatch): - '''Test folder for all instance tests.''' - rv = tmpdir.mkdir('test_apps') +def modules_tmpdir(tmpdir, monkeypatch): + '''A tmpdir added to sys.path''' + rv = tmpdir.mkdir('modules_tmpdir') monkeypatch.syspath_prepend(str(rv)) return rv @pytest.fixture -def apps_tmpdir_prefix(apps_tmpdir, monkeypatch): - monkeypatch.setattr(sys, 'prefix', str(apps_tmpdir)) - return apps_tmpdir +def modules_tmpdir_prefix(modules_tmpdir, monkeypatch): + monkeypatch.setattr(sys, 'prefix', str(modules_tmpdir)) + return modules_tmpdir @pytest.fixture -def site_packages(apps_tmpdir, monkeypatch): +def site_packages(modules_tmpdir, monkeypatch): '''Create a fake site-packages''' - rv = apps_tmpdir \ + rv = modules_tmpdir \ .mkdir('lib')\ .mkdir('python{x[0]}.{x[1]}'.format(x=sys.version_info))\ .mkdir('site-packages') @@ -91,10 +91,10 @@ def site_packages(apps_tmpdir, monkeypatch): @pytest.fixture -def install_egg(apps_tmpdir, monkeypatch): +def install_egg(modules_tmpdir, monkeypatch): '''Generate egg from package name inside base and put the egg into sys.path''' - def inner(name, base=apps_tmpdir): + def inner(name, base=modules_tmpdir): if not isinstance(name, str): raise ValueError(name) base.join(name).ensure_dir() @@ -112,9 +112,9 @@ def install_egg(apps_tmpdir, monkeypatch): import subprocess subprocess.check_call( [sys.executable, 'setup.py', 'bdist_egg'], - cwd=str(apps_tmpdir) + cwd=str(modules_tmpdir) ) - egg_path, = apps_tmpdir.join('dist/').listdir() + egg_path, = modules_tmpdir.join('dist/').listdir() monkeypatch.syspath_prepend(str(egg_path)) return egg_path return inner diff --git a/tests/test_config.py b/tests/test_config.py index 662cef2a..e273bb4b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -182,16 +182,16 @@ class TestConfig(object): class TestInstance(object): - def test_explicit_instance_paths(self, apps_tmpdir): + def test_explicit_instance_paths(self, modules_tmpdir): with pytest.raises(ValueError) as excinfo: flask.Flask(__name__, instance_path='instance') assert 'must be absolute' in str(excinfo.value) - app = flask.Flask(__name__, instance_path=str(apps_tmpdir)) - assert app.instance_path == str(apps_tmpdir) + app = flask.Flask(__name__, instance_path=str(modules_tmpdir)) + assert app.instance_path == str(modules_tmpdir) - def test_main_module_paths(self, apps_tmpdir, purge_module): - app = apps_tmpdir.join('main_app.py') + def test_main_module_paths(self, modules_tmpdir, purge_module): + app = modules_tmpdir.join('main_app.py') app.write('import flask\n\napp = flask.Flask("__main__")') purge_module('main_app') @@ -199,8 +199,8 @@ class TestInstance(object): here = os.path.abspath(os.getcwd()) assert app.instance_path == os.path.join(here, 'instance') - def test_uninstalled_module_paths(self, apps_tmpdir, purge_module): - app = apps_tmpdir.join('config_module_app.py').write( + def test_uninstalled_module_paths(self, modules_tmpdir, purge_module): + app = modules_tmpdir.join('config_module_app.py').write( 'import os\n' 'import flask\n' 'here = os.path.abspath(os.path.dirname(__file__))\n' @@ -209,10 +209,10 @@ class TestInstance(object): purge_module('config_module_app') from config_module_app import app - assert app.instance_path == str(apps_tmpdir.join('instance')) + assert app.instance_path == str(modules_tmpdir.join('instance')) - def test_uninstalled_package_paths(self, apps_tmpdir, purge_module): - app = apps_tmpdir.mkdir('config_package_app') + def test_uninstalled_package_paths(self, modules_tmpdir, purge_module): + app = modules_tmpdir.mkdir('config_package_app') init = app.join('__init__.py') init.write( 'import os\n' @@ -223,9 +223,9 @@ class TestInstance(object): purge_module('config_package_app') from config_package_app import app - assert app.instance_path == str(apps_tmpdir.join('instance')) + assert app.instance_path == str(modules_tmpdir.join('instance')) - def test_installed_module_paths(self, apps_tmpdir, apps_tmpdir_prefix, + def test_installed_module_paths(self, modules_tmpdir, modules_tmpdir_prefix, purge_module, site_packages, limit_loader): site_packages.join('site_app.py').write( 'import flask\n' @@ -235,12 +235,12 @@ class TestInstance(object): from site_app import app assert app.instance_path == \ - apps_tmpdir.join('var').join('site_app-instance') + modules_tmpdir.join('var').join('site_app-instance') - def test_installed_package_paths(self, limit_loader, apps_tmpdir, - apps_tmpdir_prefix, purge_module, + def test_installed_package_paths(self, limit_loader, modules_tmpdir, + modules_tmpdir_prefix, purge_module, monkeypatch): - installed_path = apps_tmpdir.mkdir('path') + installed_path = modules_tmpdir.mkdir('path') monkeypatch.syspath_prepend(installed_path) app = installed_path.mkdir('installed_package') @@ -250,10 +250,10 @@ class TestInstance(object): from installed_package import app assert app.instance_path == \ - apps_tmpdir.join('var').join('installed_package-instance') + modules_tmpdir.join('var').join('installed_package-instance') - def test_prefix_package_paths(self, limit_loader, apps_tmpdir, - apps_tmpdir_prefix, purge_module, + def test_prefix_package_paths(self, limit_loader, modules_tmpdir, + modules_tmpdir_prefix, purge_module, site_packages): app = site_packages.mkdir('site_package') init = app.join('__init__.py') @@ -262,18 +262,18 @@ class TestInstance(object): import site_package assert site_package.app.instance_path == \ - apps_tmpdir.join('var').join('site_package-instance') + modules_tmpdir.join('var').join('site_package-instance') - def test_egg_installed_paths(self, install_egg, apps_tmpdir, - apps_tmpdir_prefix): - apps_tmpdir.mkdir('site_egg').join('__init__.py').write( + def test_egg_installed_paths(self, install_egg, modules_tmpdir, + modules_tmpdir_prefix): + modules_tmpdir.mkdir('site_egg').join('__init__.py').write( 'import flask\n\napp = flask.Flask(__name__)' ) install_egg('site_egg') try: import site_egg assert site_egg.app.instance_path == \ - str(apps_tmpdir.join('var/').join('site_egg-instance')) + str(modules_tmpdir.join('var/').join('site_egg-instance')) finally: if 'site_egg' in sys.modules: del sys.modules['site_egg'] diff --git a/tests/test_ext.py b/tests/test_ext.py index 8f57dd12..68431ecf 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -55,28 +55,28 @@ def importhook_setup(monkeypatch, request): @pytest.fixture -def newext_simple(apps_tmpdir): - x = apps_tmpdir.join('flask_newext_simple.py') +def newext_simple(modules_tmpdir): + x = modules_tmpdir.join('flask_newext_simple.py') x.write('ext_id = "newext_simple"') @pytest.fixture -def oldext_simple(apps_tmpdir): - flaskext = apps_tmpdir.mkdir('flaskext') +def oldext_simple(modules_tmpdir): + flaskext = modules_tmpdir.mkdir('flaskext') flaskext.join('__init__.py').write('\n') flaskext.join('oldext_simple.py').write('ext_id = "oldext_simple"') @pytest.fixture -def newext_package(apps_tmpdir): - pkg = apps_tmpdir.mkdir('flask_newext_package') +def newext_package(modules_tmpdir): + pkg = modules_tmpdir.mkdir('flask_newext_package') pkg.join('__init__.py').write('ext_id = "newext_package"') pkg.join('submodule.py').write('def test_function():\n return 42\n') @pytest.fixture -def oldext_package(apps_tmpdir): - flaskext = apps_tmpdir.mkdir('flaskext') +def oldext_package(modules_tmpdir): + flaskext = modules_tmpdir.mkdir('flaskext') flaskext.join('__init__.py').write('\n') oldext = flaskext.mkdir('oldext_package') oldext.join('__init__.py').write('ext_id = "oldext_package"') @@ -85,8 +85,8 @@ def oldext_package(apps_tmpdir): @pytest.fixture -def flaskext_broken(apps_tmpdir): - ext = apps_tmpdir.mkdir('flask_broken') +def flaskext_broken(modules_tmpdir): + ext = modules_tmpdir.mkdir('flask_broken') ext.join('b.py').write('\n') ext.join('__init__.py').write('import flask.ext.broken.b\n' 'import missing_module') diff --git a/tests/test_helpers.py b/tests/test_helpers.py index bdc4c282..872906d8 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -577,8 +577,8 @@ class TestNoImports(object): imp modules in the Python standard library. """ - def test_name_with_import_error(self, apps_tmpdir): - apps_tmpdir.join('importerror.py').write('raise NotImplementedError()') + def test_name_with_import_error(self, modules_tmpdir): + modules_tmpdir.join('importerror.py').write('raise NotImplementedError()') try: flask.Flask('importerror') except NotImplementedError: