pytest bdd目录结构
时间: 2023-07-27 12:06:35 浏览: 97
When organizing pytest-bdd tests, you can follow a directory structure that makes it easy to manage and execute your BDD scenarios. Here's a common pytest-bdd directory structure:
```
project/
├── features/
│ ├── support/
│ │ ├── environment.py
│ │ └── steps/
│ │ └── step_definitions.py
│ ├── feature1.feature
│ └── feature2.feature
└── tests/
├── conftest.py
└── test_*.py
```
Let's break down each component of this directory structure:
- `features/`: This directory contains all the feature files (`*.feature`) that describe your BDD scenarios. Each feature file contains one or more scenarios with their corresponding steps.
- `features/support/`: This directory is used to store support code and configuration for your BDD tests.
- `features/support/environment.py`: This Python file is used to define the pytest-bdd environment. You can configure hooks, fixtures, and other settings here.
- `features/support/steps/`: This directory contains step definition files (`*_definitions.py`). Each step definition file defines the code implementation for the steps mentioned in the feature files.
- `tests/`: This directory is used to store any additional tests or test-related code that is not specific to BDD. For example, you might have unit tests or integration tests here.
- `tests/conftest.py`: This Python file is a pytest configuration file where you can define fixtures, plugins, and other test-related configurations.
- `tests/test_*.py`: These Python files contain additional tests that are not written using BDD. You can organize your tests into multiple files based on different test scenarios or test areas.
By following this directory structure, you can keep your BDD scenarios, step definitions, and other test-related code organized and easy to maintain. You can run your pytest-bdd tests by executing `pytest` in the root directory of your project, and pytest will discover and execute the tests based on this structure.
阅读全文