Commits

Ronny Pfannschmidt  committed 6e09486

fix sessionstart handling

  • Participants
  • Parent commits 451a5a2

Comments (0)

Files changed (3)

File pytest_couchdbkit/__init__.py

+import pytest
 from .dumper import dump_db
 from .utils import server_from_config, dbname_from_config, \
         maybe_destroy_and_create
     pluginmanager.addhooks(hookspec)
 
 def pytest_sessionstart(session):
-    server = server_from_config(session.config)
-    dbname = dbname_from_config(session.config, 'pytest_%s_couchapp_source')
-    #db = maybe_destroy_and_create(server, dbname)
-    session.config.hook.pytest_couchdbkit_push_app(server=server, dbname=dbname)
+    try:
+        dbname = dbname_from_config(session.config, 'pytest_%s_couchapp_source')
+    except pytest.xfail.Exception:
+        pass # we are not configured
+    else:
+        server = server_from_config(session.config)
+        session.config.hook.pytest_couchdbkit_push_app(
+                server=server,
+                dbname=dbname)
 
 def pytest_funcarg__couchdb_server(request):
     return server_from_config(request.config)

File pytest_couchdbkit/utils.py

 
 def server_from_config(config):
     from couchdbkit import Server
-    backend = config.getini('couchdbkit_backend')
+    backend = config.getini('couchdbkit_backend') or 'thread'
     return Server(backend=backend)
 
 def dbname_from_config(config, fmt):

File testing/test_hooks.py

     assert tmpdir.join('couchdb.dump').check()
 
 
+def test_sessionstart_handles_missing_dbconfig_gracefull():
+    session = mock.Mock()
+    session.config.getini.side_effect = {}.get
+    pytest_couchdbkit.pytest_sessionstart(session)
+
+
+def test_sessionstart_with_config_calls_hook():
+    settings = {'couchdbkit_suffix':'test'}
+    session = mock.Mock()
+    session.config.getini.side_effect = settings.get
+    pytest_couchdbkit.pytest_sessionstart(session)
+    call_args = session.config.hook.pytest_couchdbkit_push_app.call_args
+    assert call_args[1]['dbname'] == 'pytest_test_couchapp_source'
+
+
 def test_replication(request, tmpdir):
     server = pytest_couchdbkit.pytest_funcarg__couchdb_server(request)
     db_source = maybe_destroy_and_create(server, 'pytest_test_couchapp_source')