def test_add_test_cleanup_from_session_scope_forbidden(checkpoint): with slash.Session(): with pytest.raises(IncorrectScope): slash.add_cleanup(checkpoint, scope='test') assert not checkpoint.called
def __code__(): # pylint: disable=unused-variable import gossip # pylint: disable=reimported # pylint: disable=undefined-variable,unused-variable def session_cleanup_callback(): __ut__.events.add('session_cleanup') slash.add_cleanup(session_cleanup_callback, scope='session') @gossip.register('slash.test_end') def test_end_callback(): __ut__.events.add('test_end')
def __code__(): # pylint: disable=unused-variable import gossip # pylint: disable=redefined-outer-name,reimported # pylint: disable=undefined-variable,unused-variable def session_cleanup_callback(): __ut__.events.add('session_cleanup') slash.add_cleanup(session_cleanup_callback, scope='session') @gossip.register('slash.test_end') def test_end_callback(): __ut__.events.add('test_end')
def test_test_scoped_cleanups_in_session(checkpoint): # with scoped cleanups, and the default being 'test', there is a special meaning # for cleanups registered outside of tests.... with slash.Session() as s: slash.add_cleanup(checkpoint) assert not checkpoint.called with s.get_started_context(): pass assert not checkpoint.called assert checkpoint.called
def butler_client(): butler_server = ButlerTest.Server('http://localhost:8888') butler_client = ButlerTest.Client('http://localhost:8888') butler_server.run_async() time.sleep(0.3) def stop_server(): butler_client.get_stop() time.sleep(0.3) slash.add_cleanup(stop_server, scope='session') return butler_client
def test_cleanups_within_cleanups_preserve_scope(checkpoint1): """Cleanups added from within other cleanups should happen within the scope of the parent cleanups """ @slash.parametrize('x', [1, 2]) def test_something(x): pass with slash.Session() as s: [fake_test1, fake_test2] = Loader().get_runnables(test_something) # pylint: disable=unbalanced-tuple-unpacking s.scope_manager.begin_test(fake_test1) def cleanup(): slash.add_cleanup(checkpoint1) slash.add_cleanup(cleanup) assert not checkpoint1.called s.scope_manager.end_test(fake_test1) assert checkpoint1.called
def test_cleanups_within_cleanups_preserve_scope(checkpoint1): """Cleanups added from within other cleanups should happen within the scope of the parent cleanups """ @slash.parametrize('x', [1, 2]) def test_something(x): # pylint: disable=unused-argument pass with slash.Session() as s: [fake_test1, fake_test2] = Loader().get_runnables(test_something) # pylint: disable=unbalanced-tuple-unpacking s.scope_manager.begin_test(fake_test1) def cleanup(): slash.add_cleanup(checkpoint1) slash.add_cleanup(cleanup) assert not checkpoint1.called s.scope_manager.end_test(fake_test1) assert checkpoint1.called
def test_something(): assert not slash.is_in_cleanup() assert slash.get_current_cleanup_phase() is None def session_cleanup(): assert slash.is_in_cleanup() assert slash.get_current_cleanup_phase() == 'session' slash.add_cleanup(session_cleanup, scope='session') def module_cleanup(): assert slash.is_in_cleanup() assert slash.get_current_cleanup_phase() == 'module' slash.add_cleanup(module_cleanup, scope='module') def regular_cleanup(): assert slash.is_in_cleanup() assert slash.get_current_cleanup_phase() == 'test' slash.add_cleanup(regular_cleanup)
def test1(self_): self.events.test1() slash.add_cleanup(self.events.cleanup, "test1 cleanup 2") slash.add_cleanup(self.events.cleanup, "test1 cleanup 1")
def __code__(): def callback(): __ut__.events.add('success_only_cleanup_called') # pylint: disable=undefined-variable slash.add_cleanup(callback, success_only=True) slash.skip_test()
def test_end(): slash.add_cleanup(checkpoint, scope='session')
def test_something(): slash.add_cleanup(cleanup)
def cleanup(): slash.add_cleanup(checkpoint1)
def test(self_): slash.add_cleanup(self.events.cleanup, 1) slash.add_cleanup(self.events.cleanup, 2) raise Exception("!!!")
def __code__(): # pylint: disable=unused-variable def cleanup(): slash.context.result.data['ok'] = True slash.add_cleanup(cleanup, scope='session')
def test_1(): result = slash.context.result def cleanup(): result.add_error('this is a deferred error from test_1') slash.add_cleanup(cleanup, scope='module')
def test_end(): with pytest.raises(CannotAddCleanup): slash.add_cleanup(checkpoint)
def _do_test_callback(self, _): slash.add_cleanup(self._regular_cleanup) slash.add_critical_cleanup(self._critical_cleanup) raise KeyboardInterrupt()
def test2(self_): self.events.test2() slash.add_cleanup(self.events.cleanup, "test2 cleanup")
def test_cleanup_args_kwargs_deprecated(): with slash.Session() as s: slash.add_cleanup(lambda: None, "arg1", arg2=1) [w] = s.warnings assert 'deprecated' in str(w).lower()
def test_cleanups_before_session_start_get_deferred(checkpoint): with slash.Session() as s: slash.add_cleanup(checkpoint) with s.get_started_context(): assert not checkpoint.called assert checkpoint.called_count == 1
def session_start(): slash.add_cleanup(events.append, args=(('session_cleanup', 1), )) slash.add_cleanup(events.append, args=(('session_cleanup', 2), ))
def test_cleanups_without_session_start_never_called(checkpoint): assert not checkpoint.called with slash.Session(): slash.add_cleanup(checkpoint) assert not checkpoint.called assert not checkpoint.called
def test_cannot_add_cleanup_without_active_session(): with pytest.raises(RuntimeError): slash.add_cleanup(lambda: None)
def __code__(): def callback(): __ut__.events.add('success_only_cleanup_called') slash.add_cleanup(callback, success_only=True) slash.skip_test()
def __code__(): def cleanup(): slash.context.result.data['fixture_called'] = True slash.add_cleanup(cleanup, scope='test')
def test_partial_cleanup(): slash.add_cleanup(functools.partial(cleanup_with_argument, 5))