Test Automation With Python Part 2 PDF
Test Automation With Python Part 2 PDF
Test Automation With Python Part 2 PDF
Python
Part 2: Test suites, pre/post conditions, fixtures
Agenda
● Re-cap
● Pre-conditions / cleanups
● Test suites
● Fixtures
● Practice (writing a test suite)
● Running tests
● [if we have time] allure steps
Let’s recap what
we did before
Pytest
● Recognizes tests
● Allows to run them through command-line
● Provides assertions
● Provides pre / conditions cleanups
● Logging / reporting / tagging support
Let’s install it
# to install something, the best way is to use pip:
Option 2:
# then, run:
$ pip freeze
There are multiple ways. Today, we’ll use functions for tests.
How to write tests with pytest
A function must start with the word test. This way, pytest will recognize the test
and be able to run it:
How to run the tests
$ pytest
# OR:
$ pytest /path/to/test
# OR:
Just click the green arrow near the test in PyCharm :)
# OR:
Just right-click on the test file surface and select “run
pytest in ...”
Let’s practice a bit
Re-write your test so that it’s
recognized by pytest.
Pre-conditions / cleanups
Pre-conditions / cleanups
Fixture is a python decorator. It allows doing things before / after the test, or
provide values to a test.
Fixture - providing a value
Fixture - doing something before test
Fixture - doing something after test
Fixture - scope
Scope lets you specify what part of the tests a fixture should be applied to.