def test_get_config_yaml(tmpdir): f = tmpdir.join('config.yml') f.write('TEST_VAR: true') config = get_config('pypi_portal.config.Testing', yaml_files=[str(f)]) assert config.TEST_VAR is True
def parse_options(): """Parses command line options for Flask. Returns: Config instance to pass into create_app(). """ # Figure out which class will be imported. if OPTIONS['--config_prod']: config_class_string = 'pypi_portal.config.Production' else: config_class_string = 'pypi_portal.config.Config' config_obj = get_config(config_class_string) return config_obj
@pytest.fixture(autouse=True, scope='session') def create_all(): """Create all database tables.""" db.create_all() @pytest.fixture(scope='session') def alter_xmlrpc(request): """Replaces the ServerProxy class in the xmlrpclib library with a fake class. Class is restored after testing. """ old_method = xmlrpclib.ServerProxy xmlrpclib.ServerProxy = FakeServerProxy def func(value): FakeServerProxy.VALUE = value def fin(): xmlrpclib.ServerProxy = old_method request.addfinalizer(fin) return func # Initialize the application and sets the app context to avoid needing 'with app.app_context():'. # This must happen before any Celery tasks are imported automatically by py.test during test discovery. create_app(get_config('pypi_portal.config.Testing')).app_context().push()