From 7fe09b6e9f60cedb50022bd6f940219943a7fd2c Mon Sep 17 00:00:00 2001 From: Sonny V Date: Fri, 23 Jul 2021 00:32:35 +0200 Subject: [PATCH] style: import specific jinja attrs This avoids a false positive for B701, https://github.com/PyCQA/bandit/issues/711 Also ran black and added docstring --- pytest_generator/generate_tests.py | 9 +++++---- tests/pytest_generator/test_generate_tests.py | 4 +--- tests/pytest_generator/test_main.py | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pytest_generator/generate_tests.py b/pytest_generator/generate_tests.py index d17b560..72b8572 100644 --- a/pytest_generator/generate_tests.py +++ b/pytest_generator/generate_tests.py @@ -9,15 +9,16 @@ from types import MethodType, ModuleType from typing import Any, Callable, Optional -import jinja2 +from jinja2 import Environment, FileSystemLoader, select_autoescape -env = jinja2.Environment( - loader=jinja2.FileSystemLoader(Path(__file__).parent.parent / "templates"), - autoescape=jinja2.select_autoescape(), +env = Environment( + loader=FileSystemLoader(Path(__file__).parent.parent / "templates"), + autoescape=select_autoescape(), ) def generate(root: Path): + """Generate tests for all modules under `root`.""" if not root.is_absolute(): root = root.absolute() diff --git a/tests/pytest_generator/test_generate_tests.py b/tests/pytest_generator/test_generate_tests.py index 4c34705..449e51d 100644 --- a/tests/pytest_generator/test_generate_tests.py +++ b/tests/pytest_generator/test_generate_tests.py @@ -1,6 +1,6 @@ import pytest -from pytest_generator import generate_tests +from pytest_generator import generate_tests @pytest.mark.parametrize(("expected_output"), [("x")]) @@ -9,14 +9,12 @@ def test_generate_tests_generate(expected_output): assert return_value == expected_output - @pytest.mark.parametrize(("expected_output"), [("x")]) def test_generate_tests__get_local_members(expected_output): return_value = generate_tests._get_local_members() assert return_value == expected_output - @pytest.mark.parametrize(("expected_output"), [("x")]) def test_generate_tests__collect_members_and_write_tests(expected_output): return_value = generate_tests._collect_members_and_write_tests() diff --git a/tests/pytest_generator/test_main.py b/tests/pytest_generator/test_main.py index fef9e9c..e4a60f5 100644 --- a/tests/pytest_generator/test_main.py +++ b/tests/pytest_generator/test_main.py @@ -1,6 +1,6 @@ import pytest -from pytest_generator import main +from pytest_generator import main @pytest.mark.parametrize(("expected_output"), [("x")])