Best Python code snippet using sure_python
test.py
Source:test.py
1import requests2import pytest3def rlog(msg):4 """ A dummy function that injects msg into trace log """5 #print(msg)6 pass7def calc_sum(a,b):8 return a+b9def check_sum(a,b,result):10 assert a + b == result11def fails():12 raise AssertionError()13@pytest.fixture14def fixtureWithSetup():15 rlog("setup")16@pytest.fixture17def fixtureWithSetupAndTeardown1():18 rlog("setup")19 yield20 rlog("teardown")21@pytest.fixture22def fixtureWithSetupAndTeardown2():23 rlog("setup2")24 yield25 rlog("teardown2")26@pytest.fixture(scope="module")27def moduleFixture():28 rlog("module setup")29 yield30 rlog("module teardown")31@pytest.fixture(scope="module")32def moduleFixtureWithSetupError():33 assert False34 yield35 rlog("module teardown")36@pytest.fixture37def fixtureWithSetupError():38 assert False39@pytest.fixture40def fixtureWithTeardownError():41 rlog("setup")42 yield43 assert False44@pytest.fixture45def testFixture2():46 rlog("setup2")47 yield48 rlog("teardown2")49@pytest.mark.passing50def test_passing_test():51 """ A simple passing test """52 sum = calc_sum(1,2)53 check_sum(1,2,sum)54@pytest.mark.failing55def test_direct_assert():56 """ A test that fails with inlined assertion error """57 rlog("here!")58 raise AssertionError("foo")59@pytest.mark.failing60def test_keyword_assert():61 """ A test that fails within keyword """62 check_sum(1,2,4)63@pytest.mark.passing64def test_fixture_setup(fixtureWithSetup):65 """ A test with a fixture with a setup """66 rlog("here")67@pytest.mark.passing68def test_fixture_setup_and_teardown(fixtureWithSetupAndTeardown1):69 """ A test with passing fixture setup and teardown """70 rlog("here")71@pytest.mark.passing72def test_two_fixtures(fixtureWithSetupAndTeardown1, fixtureWithSetupAndTeardown2):73 """ A test with two function-scoped fixtures """74 rlog("here")75@pytest.mark.passing76def test_module_and_test_fixtures(moduleFixture, fixtureWithSetupAndTeardown1):77 """ A test with one module-scoped and one function-scoped fixture """78 rlog("here")79@pytest.mark.failing80def test_setup_assert(fixtureWithSetupError):81 """ A test that fails in fixture setup phase """82 rlog("here")83@pytest.mark.failing84def test_module_setup_assert(moduleFixtureWithSetupError):85 """ A test that fails in module fixture setup phase """86 rlog("here")87@pytest.mark.failing88def test_assert_in_test_body(fixtureWithSetupAndTeardown1):89 """ A test that fails in test body """90 rlog("here")91 assert False92@pytest.mark.failing93def test_assert_in_test_body_indirect(fixtureWithSetupAndTeardown1):94 """ A test that fails in a function called by test body"""95 rlog("here")96 fails()97@pytest.mark.failing98def test_teardown_assert(fixtureWithTeardownError):99 """ A test that fails in fixture teardown phase """100 rlog("here")101@pytest.mark.failing102def test_assert_in_test_body_and_teardown(fixtureWithTeardownError):103 """ A test that fails in fixture setup and teardown phase """104 rlog("here")...
should_suppress_error_during_teardown_tests.py
Source:should_suppress_error_during_teardown_tests.py
1# -*- coding: utf-8 -*-2#3# This file is part of PyBuilder4#5# Copyright 2011-2020 PyBuilder Team6#7# Licensed under the Apache License, Version 2.0 (the "License");8# you may not use this file except in compliance with the License.9# You may obtain a copy of the License at10#11# http://www.apache.org/licenses/LICENSE-2.012#13# Unless required by applicable law or agreed to in writing, software14# distributed under the License is distributed on an "AS IS" BASIS,15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16# See the License for the specific language governing permissions and17# limitations under the License.18import unittest19from itest_support import IntegrationTestSupport20__author__ = 'arcivanov'21class Test(IntegrationTestSupport):22 def test(self):23 self.write_build_file("""24from pybuilder.core import task, before, after25@task26def foo():27 raise ValueError("simulated task failure")28@after(["foo"], teardown=True)29def teardown1_foo(project):30 raise ArithmeticError("simulated teardown error")31@after(["foo"], teardown=True)32def teardown2_foo(project):33 project.set_property("teardown2_foo completed", True)34 """)35 reactor = self.prepare_reactor()36 project = reactor.project37 self.assertRaises(ValueError, reactor.build, "foo")38 self.assertTrue(project.get_property("teardown2_foo completed"))39if __name__ == "__main__":...
pytest_teardown.py
Source:pytest_teardown.py
...17#18def test_teardown1(load_dataset):19 assert len(load_dataset) == 420 print("Finished test_teardown1")21def test_teardown2(load_dataset):22 assert len(load_dataset) == 423 print("Finished test_teardown2")24def test_teardown3(load_dataset):25 assert len(load_dataset) == 4...
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!!