pytest-csv-params/tests/plugin/test_plugin.py

99 lines
3.6 KiB
Python

"""
Plugin Calls
============
**Module:** ``tests.plugin.test_plugin``
"""
from typing import Callable
from _pytest.pytester import Pytester
def test_plugin_test_multiplication(
pytester: Pytester, simple_test_csv: str, simple_fruit_test: Callable[[str], str]
) -> None:
"""
Test a simple round trip (positive test case)
:param pytester: Pytester fixture
:param simple_test_csv: Fixture :meth:`~tests.plugin.conftest.simple_test_csv`
:param simple_fruit_test: Fixture :meth:`~tests.plugin.conftest.simple_fruit_test`
"""
csv_file = str(pytester.makefile(".csv", simple_test_csv).absolute())
pytester.makepyfile(simple_fruit_test(csv_file))
result = pytester.runpytest("-p", "no:bandit")
result.assert_outcomes(passed=3, failed=1)
def test_plugin_test_error(pytester: Pytester, bad_test_csv: str, simple_fruit_test: Callable[[str], str]) -> None:
"""
Test if a test error is correctly recognized
:param pytester: Pytester fixture
:param bad_test_csv: Fixture :meth:`~tests.plugin.conftest.bad_test_csv`
:param simple_fruit_test: Fixture :meth:`~tests.plugin.conftest.simple_fruit_test`
"""
csv_file = str(pytester.makefile(".csv", bad_test_csv).absolute())
pytester.makepyfile(simple_fruit_test(csv_file))
result = pytester.runpytest("-p", "no:bandit")
result.assert_outcomes(errors=1)
def test_plugin_test_text_shorthand(
pytester: Pytester, text_test_csv: str, simple_text_test: Callable[[str], str]
) -> None:
"""
Test the shorthand version of the plugin's decorator
:param pytester: Pytester fixture
:param text_test_csv: Fixture :meth:`~tests.plugin.conftest.text_test_csv`
:param simple_text_test: Fixture :meth:`~tests.plugin.conftest.simple_text_test`
"""
csv_file = str(pytester.makefile(".csv", text_test_csv).absolute())
pytester.makepyfile(simple_text_test(csv_file))
result = pytester.runpytest("-p", "no:bandit")
result.assert_outcomes(passed=2, failed=1)
def test_plugin_all_tests_at_once( # pylint: disable=too-many-arguments
pytester: Pytester,
text_test_csv: str,
bad_test_csv: str,
simple_test_csv: str,
simple_fruit_test: Callable[[str, str], str],
simple_text_test: Callable[[str], str],
) -> None:
"""
This is a meta test to check if multiple files would work also. Basically, it's a combination of all the other
plugin invocation tests of the module :mod:`tests.plugin.test_plugin`.
We can't run the error-prone test here, because it would stop all tests.
:param pytester: Pytester fixture
:param text_test_csv: Fixture :meth:`~tests.plugin.conftest.text_test_csv`
:param bad_test_csv: Fixture :meth:`~tests.plugin.conftest.bad_test_csv`
:param text_test_csv: Fixture :meth:`~tests.plugin.conftest.text_test_csv`
:param simple_fruit_test: Fixture :meth:`~tests.plugin.conftest.simple_fruit_test`
:param simple_text_test: Fixture :meth:`~tests.plugin.conftest.simple_text_test`
"""
csv_file_text = str(pytester.makefile(".1.csv", text_test_csv).absolute())
pytester.makepyfile(test_plugin_test_all_one=simple_text_test(csv_file_text))
csv_file_bad = str(pytester.makefile(".2.csv", bad_test_csv).absolute())
pytester.makepyfile(test_plugin_test_all_two=simple_fruit_test(csv_file_bad, "bad_one"))
csv_file_good = str(pytester.makefile(".3.csv", simple_test_csv).absolute())
pytester.makepyfile(test_plugin_test_all_three=simple_fruit_test(csv_file_good, "good_one"))
result = pytester.runpytest("-p", "no:bandit", "test_plugin_test_all_one.py", "test_plugin_test_all_three.py")
result.assert_outcomes(passed=5, failed=2, errors=0)