Adopt modern pytest features to create maintainable, isolated, and comprehensive tests. This includes: 1. **Prefer pytest over unittest** for new test development to leverage pytest's rich feature set and simpler syntax.
Adopt modern pytest features to create maintainable, isolated, and comprehensive tests. This includes:
Prefer pytest over unittest for new test development to leverage pytest’s rich feature set and simpler syntax.
Use parameterization for testing multiple scenarios instead of duplicating test code: ```python
for graph_framework in [“NETWORKX”, “RUSTWORKX”]: # test code with graph_framework…
@pytest.mark.parametrize(“graph_framework”, [“NETWORKX”, “RUSTWORKX”]) def test_connected_node_with_framework(graph_framework): # test code with graph_framework…
3. **Maintain test isolation** by using fixtures like `monkeypatch` to modify environment variables or dependencies for a single test:
```python
# Instead of modifying environment directly:
def test_get_folder_definitions_do_not_ignore_hidden(self):
os.environ["CKV_IGNORE_HIDDEN_DIRECTORIES"] = "False"
# test code...
# Use monkeypatch for isolated modifications:
def test_get_folder_definitions_do_not_ignore_hidden(monkeypatch):
monkeypatch.setenv("CKV_IGNORE_HIDDEN_DIRECTORIES", "False")
# test code...
Following these practices will result in tests that are easier to maintain, less prone to side effects, and provide clearer failure information.
Enter the URL of a public GitHub repository