由 neevop 七月 3, 2023
Configuration
可以查看官方文档:https://docs.pytest.org/en/latest/customize.html
pytest.ini
# put a section marker at the top
[pytest]
# line continuation
# indent continued line by 2 spaces.
norecursedirs =
.git
.idea
# norecursdir
# allow only simple directory names or patterns without /, they are always applied in all subdirectories, for individual directories use 'addopts --ignore='
# addopts
addopts = --ignore=./some/dir --ignore=./some/other/dir --ignore=./dir1/some.file
using cmd parameters in pytest
# read from cmd in conftest.py file
def pytest_addoption(parser):
parser.addoption("--env", action="store", default="environment value is not provided")
def pytest_sessionstart(session):
env_param = session.config.getoption("--env")
# set param using os.getenv
os.environ['env'] = env_param
os.getenv['env']
# supply param from cmd
pytest tests/ --env qa