-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def setup_module(module): | |
| print("\nSetup module") | |
| def teardown_module(module): | |
| print("\nTeardown module") | |
| def setup_function(function): | |
| if function == test1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| @pytest.fixture() | |
| def setup(): | |
| print("\nSetup") | |
| def test1(setup): | |
| print("Executing test 1") | |
| assert True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| @pytest.fixture(autouse=True) | |
| def setup(): | |
| print("\nSetup") | |
| def test1(): | |
| print("Executing test 1") | |
| assert True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| @pytest.fixture() | |
| def setup1(): | |
| print("\nSetup 1") | |
| yield | |
| print("\nTeardown 1") | |
| @pytest.fixture() | |
| def setup2(request): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| @pytest.fixture(scope="session", autouse=True) | |
| def setupSession(): | |
| print("\nSetup Session") | |
| @pytest.fixture(scope="module", autouse=True) | |
| def setupModule(): | |
| print("\nSetup Module") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| @pytest.fixture(scope="module", autouse=True) | |
| def setupModule2(): | |
| print("\nSetup module2") | |
| @pytest.fixture(scope="class", autouse=True) | |
| def setupClass2(): | |
| print("\nSetup Class2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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 – Just another WordPress site</title> | |
| <meta name='robots' content='noindex,nofollow' /> |