Skip to content

Instantly share code, notes, and snippets.

View tjkhara's full-sized avatar

tjkhara

View GitHub Profile
@tjkhara
tjkhara / test_function_file.py
Created October 18, 2020 16:13
setup and tear down in functions
def setup_module(module):
print("\nSetup module")
def teardown_module(module):
print("\nTeardown module")
def setup_function(function):
if function == test1:
@tjkhara
tjkhara / test_fixture_file_1.py
Created October 18, 2020 16:20
Fixture file 1
import pytest
@pytest.fixture()
def setup():
print("\nSetup")
def test1(setup):
print("Executing test 1")
assert True
@tjkhara
tjkhara / test_autouse_file.py
Created October 18, 2020 16:22
Autouse in fixture
import pytest
@pytest.fixture(autouse=True)
def setup():
print("\nSetup")
def test1():
print("Executing test 1")
assert True
@tjkhara
tjkhara / test_two_teardown_options.py
Created October 18, 2020 16:32
Two teardown options
import pytest
@pytest.fixture()
def setup1():
print("\nSetup 1")
yield
print("\nTeardown 1")
@pytest.fixture()
def setup2(request):
@tjkhara
tjkhara / test_fixture_scope.py
Created October 18, 2020 16:38
Fixture scope
import pytest
@pytest.fixture(scope="session", autouse=True)
def setupSession():
print("\nSetup Session")
@pytest.fixture(scope="module", autouse=True)
def setupModule():
print("\nSetup Module")
@tjkhara
tjkhara / test_fixture_class_scope.py
Created October 18, 2020 16:44
Fixture class scope
import pytest
@pytest.fixture(scope="module", autouse=True)
def setupModule2():
print("\nSetup module2")
@pytest.fixture(scope="class", autouse=True)
def setupClass2():
print("\nSetup Class2")
@tjkhara
tjkhara / test_fixtures_passing_data.py
Created October 18, 2020 16:51
Fixtures - passing data
import pytest
# The text fixture and unit test are both run once for each value
# specified in the params list
@pytest.fixture(params=[1,2,3])
def setup(request):
retVal = request.param
print(f"\nSetup! retVal={retVal}")
return retVal
@tjkhara
tjkhara / test_asset_ex1.py
Created October 18, 2020 16:56
Assert example 1
# Using assert statements and exceptions
def test_IntAssert():
assert 1 == 1
def test_StrAssert():
assert "str" == "str"
def test_floatAssert():
assert 1.0 == 1.0
@tjkhara
tjkhara / pytest_useful_commandline_arguments.md
Created October 18, 2020 17:05
Pytest useful command line arguments

PyTest Useful Command Line Arguments

  • Pass in module name

  • Pass in directory path

  • -k option this matches expressions

  • -m This matches tests that have a pytest.mark decorator

    -v is for verbose output -q is for quiet mode -s do not capture console output

@tjkhara
tjkhara / get_response_wc
Created October 24, 2020 14:24
response from woo commerce
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2.0">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="http://localhost:11002/xmlrpc.php">
<title>Backend API Testing &#8211; Just another WordPress site</title>
<meta name='robots' content='noindex,nofollow' />