Best Python code snippet using slash
test_variation_info.py
Source:test_variation_info.py
...37 @slash.fixture38 def fixture():39 pass40 s.fixture_store.resolve()41 with s.get_started_context():42 slash.runner.run_tests(make_runnable_tests(test_something))43 assert s.results.is_success(allow_skips=False)44 assert checkpoint.called45def test_parametrization_info_values_include_nested_fixture_values():46 value1 = str(uuid4())47 value2 = str(uuid4())48 @gossip.register('slash.test_start')49 def test_start_hook():50 slash.context.result.data['variation_values'] = slash.context.test.__slash__.variation.values.copy()51 @slash.parametrize('param', ['some_value'])52 def test_something(param, some_fixture):53 pass54 with slash.Session() as s:55 @s.fixture_store.add_fixture56 @slash.fixture57 @slash.parametrize('value', [value1, value2])58 def some_fixture(value):59 pass60 s.fixture_store.resolve()61 with s.get_started_context():62 slash.runner.run_tests(make_runnable_tests(test_something))63 assert s.results.is_success(allow_skips=False)64 all_values = []65 for result in s.results.iter_test_results():66 values = result.data['variation_values']67 all_values.append(values['some_fixture.value'])68 assert len(all_values) == 269 assert set(all_values) == {value1, value2}70def test_variation_identification():71 value1 = str(uuid4())72 value2 = str(uuid4())73 @gossip.register('slash.test_start')74 def test_start_hook():75 variation = slash.context.test.__slash__.variation76 slash.context.result.data['variation_info'] = {77 'id': variation.id.copy(),78 'values': variation.values.copy(),79 }80 @slash.parametrize('param', ['some_value'])81 def test_something(param, some_fixture):82 pass83 with slash.Session() as s:84 @s.fixture_store.add_fixture85 @slash.fixture86 @slash.parametrize('value', [value1])87 def some_fixture(value):88 return value289 s.fixture_store.resolve()90 with s.get_started_context():91 slash.runner.run_tests(make_runnable_tests(test_something))92 assert s.results.is_success(allow_skips=False)93 [info] = [result.data['variation_info'] for result in s.results.iter_test_results()]94 assert info['id']['param'] == 095 assert info['values']['param'] == 'some_value'96 assert info['id']['some_fixture.value'] == 097 assert 'some_fixture' not in info['values']98 assert info['values']['some_fixture.value'] == value199def _freeze(dictionary):100 return frozenset(dictionary.items())101def test_variation_tuples(results):102 [res] = results.test_parametrization_tuple103 values = res.data['captured_values']104 assert values['x'] == 1105 assert values['y'] == 2106def test_nested_fixture_ids(results):107 ids = {res.data['captured_values']['outer_fixture.outer_param'] for res in results.test_nested_fixture}108 assert ids == {666}109 for res in results.test_nested_fixture:110 assert 'outer_fixture' not in res.data['captured_values']111def test_fixture_and_toggle(results):112 assert len(results.test_fixture_and_toggle) == 2113@pytest.fixture114def results():115 tests = []116 def include(f):117 tests.append(f)118 return f119 @include120 def test_no_params():121 pass122 @include123 def test_single_param_fixture(fixture):124 _capture_arguments()125 @include126 def test_nested_fixture(outer_fixture):127 _capture_arguments()128 @include129 @slash.parametrize(('x', 'y'), [(1, 2)])130 def test_parametrization_tuple(x, y):131 _capture_arguments()132 @include133 @slash.parameters.toggle('toggle')134 def test_fixture_and_toggle(fixture, toggle):135 _capture_arguments()136 with slash.Session() as s:137 @s.fixture_store.add_fixture138 @slash.fixture139 def fixture():140 return _object1141 @s.fixture_store.add_fixture142 @slash.fixture143 @slash.parametrize('x', [1, 2, 3])144 def inner_fixture(x):145 return 'inner{}'.format(x)146 @s.fixture_store.add_fixture147 @slash.fixture148 @slash.parametrize('outer_param', [666])149 def outer_fixture(inner_fixture, outer_param):150 return 'outer_{}'.format(inner_fixture)151 s.fixture_store.resolve()152 with s.get_started_context():153 slash.runner.run_tests(make_runnable_tests(tests))154 assert s.results.is_success(allow_skips=False)155 returned = collections.defaultdict(list)156 for res in s.results.iter_test_results():157 returned[res.test_metadata.function_name].append(res)158 return Munch(returned)159# helpers ################################################################################160_object1 = object()161def _capture_arguments():162 values = copy.copy(slash.context.result.test_metadata.variation.values)...
__init__.py
Source:__init__.py
...73 if session is None:74 session = slash.Session()75 stack.enter_context(session)76 test_class_path_or_iterator = make_runnable_tests(test_class_path_or_iterator)77 with session.get_started_context():78 slash.runner.run_tests(test_class_path_or_iterator)79 for result in session.results.iter_test_results():80 for err in itertools.chain(result.get_errors(), result.get_failures(), result.get_skips()):81 _logger.debug("Unsuccessful result: {0}", err)82 return session83run_tests_in_session.__test__ = False84def run_tests_assert_success(test_class_path_or_iterator, session=None):85 session = run_tests_in_session(test_class_path_or_iterator, session=session)86 assert session.results.is_success(), "Run did not succeed"87 return session88run_tests_assert_success.__test__ = False89def make_runnable_tests(thing):90 return slash.loader.Loader().get_runnables(thing)91def resolve_and_run(thing):92 slash.context.session.fixture_store.resolve()93 with slash.context.session.get_started_context():94 tests = make_runnable_tests(thing)95 slash.runner.run_tests(tests)96 return list(slash.context.session.results.iter_test_results())97def without_pyc(filename):98 if filename.endswith('.pyc'):99 return filename[:-1]100 return filename101def raises_maybe(exc, cond):102 @contextmanager103 def noop():104 yield105 if cond:106 return pytest.raises(exc)107 return noop()...
test_yield_fixture.py
Source:test_yield_fixture.py
...25 end_checkpoints[iteration]()26 def test_something(fixture):27 assert fixture == value28 s.fixture_store.resolve()29 with s.get_started_context():30 slash.runner.run_tests(make_runnable_tests(test_something))31 assert s.results.is_success(allow_skips=False)32def test_yield_fixture_with_this_argument(yield_fixture_decorator):33 iterations = [uuid4() for i in range(3)]34 value = uuid4()35 with slash.Session() as s:36 @s.fixture_store.add_fixture37 @slash.parametrize('iteration', list(iterations))38 @yield_fixture_decorator39 def fixture(this, iteration):40 yield value41 def test_something(fixture):42 assert fixture == value43 s.fixture_store.resolve()44 with s.get_started_context():45 slash.runner.run_tests(make_runnable_tests(test_something))46def test_yield_fixture_with_scope_argument(yield_fixture_decorator):47 value = str(uuid4())48 with slash.Session() as s:49 @s.fixture_store.add_fixture50 @yield_fixture_decorator(scope='session')51 def fixture():52 yield value53 def test_something(fixture):54 assert fixture == value55 s.fixture_store.resolve()56 with s.get_started_context():...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!