|
5 | 5 | from typing import Dict
|
6 | 6 | from typing import List
|
7 | 7 | from typing import Sequence
|
| 8 | +from typing import Tuple |
8 | 9 |
|
9 | 10 | import attr
|
10 | 11 | import py.path
|
11 | 12 |
|
12 | 13 | import _pytest._code
|
13 | 14 | import pytest
|
14 | 15 | from _pytest.compat import importlib_metadata
|
| 16 | +from _pytest.compat import TYPE_CHECKING |
15 | 17 | from _pytest.config import _get_plugin_specs_as_list
|
16 | 18 | from _pytest.config import _iter_rewritable_modules
|
| 19 | +from _pytest.config import _strtobool |
17 | 20 | from _pytest.config import Config
|
18 | 21 | from _pytest.config import ConftestImportFailure
|
19 | 22 | from _pytest.config import ExitCode
|
| 23 | +from _pytest.config import parse_warning_filter |
20 | 24 | from _pytest.config.exceptions import UsageError
|
21 | 25 | from _pytest.config.findpaths import determine_setup
|
22 | 26 | from _pytest.config.findpaths import get_common_ancestor
|
|
25 | 29 | from _pytest.pathlib import Path
|
26 | 30 | from _pytest.pytester import Testdir
|
27 | 31 |
|
| 32 | +if TYPE_CHECKING: |
| 33 | + from typing import Type |
| 34 | + |
28 | 35 |
|
29 | 36 | class TestParseIni:
|
30 | 37 | @pytest.mark.parametrize(
|
@@ -1829,3 +1836,52 @@ def test_conftest_import_error_repr(tmpdir):
|
1829 | 1836 | assert exc.__traceback__ is not None
|
1830 | 1837 | exc_info = (type(exc), exc, exc.__traceback__)
|
1831 | 1838 | raise ConftestImportFailure(path, exc_info) from exc
|
| 1839 | + |
| 1840 | + |
| 1841 | +def test_strtobooL(): |
| 1842 | + assert _strtobool("YES") |
| 1843 | + assert not _strtobool("NO") |
| 1844 | + with pytest.raises(ValueError): |
| 1845 | + _strtobool("unknown") |
| 1846 | + |
| 1847 | + |
| 1848 | +@pytest.mark.parametrize( |
| 1849 | + "arg, escape, expected", |
| 1850 | + [ |
| 1851 | + ("ignore", False, ("ignore", "", Warning, "", 0)), |
| 1852 | + ( |
| 1853 | + "ignore::DeprecationWarning", |
| 1854 | + False, |
| 1855 | + ("ignore", "", DeprecationWarning, "", 0), |
| 1856 | + ), |
| 1857 | + ( |
| 1858 | + "ignore:some msg:DeprecationWarning", |
| 1859 | + False, |
| 1860 | + ("ignore", "some msg", DeprecationWarning, "", 0), |
| 1861 | + ), |
| 1862 | + ( |
| 1863 | + "ignore::DeprecationWarning:mod", |
| 1864 | + False, |
| 1865 | + ("ignore", "", DeprecationWarning, "mod", 0), |
| 1866 | + ), |
| 1867 | + ( |
| 1868 | + "ignore::DeprecationWarning:mod:42", |
| 1869 | + False, |
| 1870 | + ("ignore", "", DeprecationWarning, "mod", 42), |
| 1871 | + ), |
| 1872 | + ("error:some\\msg:::", True, ("error", "some\\\\msg", Warning, "", 0)), |
| 1873 | + ("error:::mod\\foo:", True, ("error", "", Warning, "mod\\\\foo\\Z", 0)), |
| 1874 | + ], |
| 1875 | +) |
| 1876 | +def test_parse_warning_filter( |
| 1877 | + arg: str, escape: bool, expected: "Tuple[str, str, Type[Warning], str, int]" |
| 1878 | +) -> None: |
| 1879 | + assert parse_warning_filter(arg, escape=escape) == expected |
| 1880 | + |
| 1881 | + |
| 1882 | +@pytest.mark.parametrize("arg", [":" * 5, "::::-1", "::::not-a-number"]) |
| 1883 | +def test_parse_warning_filter_failure(arg: str) -> None: |
| 1884 | + import warnings |
| 1885 | + |
| 1886 | + with pytest.raises(warnings._OptionError): |
| 1887 | + parse_warning_filter(arg, escape=True) |
0 commit comments