Yes, there is, although it is easy to discuss.
I use the following test fixture py.test to make the --ini option --ini for tests. However, this approach is limited to the py.test test runner, since the other test runner does not have this flexibility.
Also my test.ini has special settings, such as disabling outgoing mail and, instead, printing to the terminal and testing the available lag.
@pytest.fixture(scope='session') def ini_settings(request): """Load INI settings for test run from py.test command line. Example: py.test yourpackage -s --ini=test.ini :return: Adictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri`` """ if not getattr(request.config.option, "ini", None): raise RuntimeError("You need to give --ini test.ini command line option to py.test to find our test settings")
Then I can configure the application (note that here pyramid.paster.bootstrap parses the configuration file again:
@pytest.fixture(scope='session') def app(request, ini_settings, **settings_overrides): """Initialize WSGI application from INI file given on the command line. TODO: This can be run only once per testing session, as SQLAlchemy does some stupid shit on import, leaks globals and if you run it again it doesn't work. Eg trying to manually call ``app()`` twice:: Class <class 'websauna.referral.models.ReferralProgram'> already has been instrumented declaratively :param settings_overrides: Override specific settings for the test case. :return: WSGI application instance as created by ``Initializer.make_wsgi_app()``. """ if not getattr(request.config.option, "ini", None): raise RuntimeError("You need to give --ini test.ini command line option to py.test to find our test settings") data = bootstrap(ini_settings["_ini_file"]) return data["app"]
In addition, configure a functional test server:
import threading import time from wsgiref.simple_server import make_server from urllib.parse import urlparse from pyramid.paster import bootstrap import pytest from webtest import TestApp from backports import typing
source share