Ronny Pfannschmidt avatar Ronny Pfannschmidt committed da766bb

add pytest-xdist support

Comments (0)

Files changed (3)

 The provided funcarg `couchdb` will be a freshly flushed database
 named `pytest_` + couchdbkit_suffix,
 additionally, after each test item,
 the database will be dumped to tmpdir.join(couchdb.dump)
 - fix breaking testruns that dont actually use it
 - add a lot of tests i should have done before 0.4
+- add support for pytest-xdist,
+  if a slave is detected, push_app wont be called,
+  and dbname gets the gw id appended
 from 0.3 to 0.4


 def pytest_sessionstart(session):
+    slaveinput = getattr(session.config, 'slaveinput', None)
+    if slaveinput is not None:
+        return
         dbname = dbname_from_config(session.config, 'pytest_%s_couchapp_source')
     except pytest.xfail.Exception:
     dbname = dbname_from_config(request.config, 'pytest_%s')
     db_source = dbname_from_config(request.config, 'pytest_%s_couchapp_source')
+    slaveinput = getattr(request.config, 'slaveinput', None)
+    if slaveinput is not None:
+        dbname = '%s_%s' % (dbname, slaveinput['slaveid'])
     db = maybe_destroy_and_create(server, dbname)
     if db_source in server.all_dbs():
         server.replicate(db_source, dbname)


     request.config.getini.side_effect = settings.get
     request.getfuncargvalue.side_effect = lambda name: funcargs(name, request)
     request.tmpdir = tmpdir
+    request.slaveinput = None
     return request
 def test_database_dumping(request, tmpdir):
     db = pytest_couchdbkit.pytest_funcarg__couchdb(request)
+    assert db.dbname == 'pytest_test'
     db.save_doc({'_id': 'test'}, force_update=True)
     finalizer = request.addfinalizer.call_args[0][0]
     assert tmpdir.join('couchdb.dump').check()
+def test_database_on_slavenode(request):
+    request.slaveinput= {'slaveid': 'gw1'}
+    db = pytest_couchdbkit.pytest_funcarg__couchdb(request)
+    assert 'gw1' in db.dbname
 def test_sessionstart_handles_missing_dbconfig_gracefull():
     session = mock.Mock()
     settings = {'couchdbkit_suffix':'test'}
     session = mock.Mock()
     session.config.getini.side_effect = settings.get
+    session.config.slaveinput = None
     call_args = session.config.hook.pytest_couchdbkit_push_app.call_args
     assert call_args[1]['dbname'] == 'pytest_test_couchapp_source'
+def test_sessionstart_on_slave_does_nothing():
+    settings = {'couchdbkit_suffix':'test'}
+    session = mock.Mock()
+    session.config.getini.side_effect = settings.get
+    session.config.slaveinput = {'slaveid': 'gw1'}
+    pytest_couchdbkit.pytest_sessionstart(session)
+    hook = session.config.hook.pytest_couchdbkit_push_app
+    assert not hook.called
 def test_replication(request, tmpdir):
     server = pytest_couchdbkit.pytest_funcarg__couchdb_server(request)
     db_source = maybe_destroy_and_create(server, 'pytest_test_couchapp_source')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.