The objective of this tutorial is to build a test repository starting with a a basic test leveraging ROAST to generate its configuration.
While ROAST is test runner agnostic, this tutorial will use pytest and
:doc:`pytest fixtures</pytest_fixtures>` developed specifically for ROAST. This means both roast
and pytest-roast
packages must be installed. While optional, it is highly recommended that
these are installed into a virtual environment.
Upon installation of pytest-roast
, pytest
will automatically be installed as a dependency.
Note
Please review :doc:`install` instructions on how to install Python packages using pip.
Tests can be structured in a number of ways. In this tutorial, we'll start with a basic structure.
Create a repository with the following structure and files:
basic/ └── tests/ ├── test_basic.py └── conf.py
conf.py
var = "hello world"
test_basic.py
import pytest
def test_basic(create_configuration):
conf = create_configuration()
assert conf["var"] == "hello world"
In test_basic.py, when pytest
is imported, all pytest fixtures will be available. Since
pytest-roast
is installed as a pytest plugin, the create_configuration
fixture is
also available and can be added as an argument to the test. When called, the configuration is read
from conf.py and assigned to the conf
variable. The value of var
is then accessed by
accessing conf["var"]
.
Note
For other methods of accessing configuration values, visit :doc:`/configuration`.
First, let's see what pytest collects as tests:
$ pytest --collect-only ======= test session starts ======== .. collected 1 item <Module tests/test_basic.py> <Function test_basic> ====== no tests ran in 0.04s =======
We can now execute the test:
$ pytest ====== test session starts ======= .. collected 1 item tests/test_basic.py . [100%] ======= 1 passed in 0.18s ========
Note
Visit :doc:`/complex_structures` for advanced parameterized and categorized testing scenarios.