Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential Bug on test_typeguard.py::test_exec_no_namespace and test_typeguard.py::test_forward_ref_policy_guess #221

Closed
lonly7star opened this issue Nov 28, 2021 · 1 comment

Comments

@lonly7star
Copy link

Describe the bug
There are also two potential bugs I detect. The first is the test on test_typeguard.py::test_exec_no_namespace, the test will fail on pytest. The second bug is on test_typeguard.py::test_forward_ref_policy_guess, where the test can pass the first test run but fail started on the second test run.

To Reproduce

for the bug on test_typeguard.py::test_exec_no_namespace

  1. run pytest pytest tests/test_typeguard.py

for the bug on test_typeguard.py::test_forward_ref_policy_guess

  1. install pytest flaky finder with pip install pytest-flakefinder
  2. run pytest with flake-finder with command pytest -k tests/test_typeguard.py --flake-finder --flake-runs=5

Expected behavior

The test_typeguard will have one fail on normal pytest run and 9 fails with flake-finder, shown as below
test_typeguard.py ......................................................................FFFFF................................................ [ 11%]
............................................................................................................................................. [ 25%]
............................................................................................................................................. [ 38%]
............................................................................................................................................. [ 52%]
............................................................................................................................................. [ 66%]
............................................................................................................................................. [ 79%]
............................................................................................................................................. [ 93%]
..............................................................FFFF.....
Where the first 5 fail is from test_exec_no_namespace and the later 4 is from test_forward_ref_policy_guess
The fail message of test_exec_no_namespace will be
tests/test_typeguard.py:161: in test_exec_no_namespace """), {})
<string>:4: in <module> ???
../.local/lib/python3.6/site-packages/typeguard/__init__.py:1015: in typechecked
warn('no type annotations present -- not typechecking {}'.format(function_name(func)))
../.local/lib/python3.6/site-packages/typeguard/__init__.py:355: in function_name
qualname = (module + '.') if module not in ('builtins', '') else ''
E TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

and for test_forward_ref_policy_guess

tests/test_typeguard.py:1528: in test_forward_ref_policy_guess
unresolvable_annotation(collections.OrderedDict())
E Failed: DID NOT WARN. No warnings of type (<class 'typeguard.TypeHintWarning'>,) was emitted. The list of emitted warnings is: [].

Additional context

For test_exec_no_namespace the reason seems related to the python library textwrap.py where it use text = re.sub(r'(?m)^' + margin, '', text) but as the error message shown, unsupported operand type(s) for +: 'NoneType' and 'str' it might related to the import context but I'm not sure.

For test_forward_ref_policy_guess the reason seems like related to the pytest warning suppressed where same warning will be emit on the second times, you can also check this issue, where it seems can be resolved by changing the pytest setup, it is also fine if the developer considers the fail on multiple runs doesn't need to be concerned.

I also create a PR fix another function on test_typeguard.py and it is this PR

@lonly7star lonly7star changed the title potential Bugon test_typeguard.py::test_exec_no_namespace and test_typeguard.py::test_forward_ref_policy_guess potential Bug on test_typeguard.py::test_exec_no_namespace and test_typeguard.py::test_forward_ref_policy_guess Nov 28, 2021
@agronholm
Copy link
Owner

I've fixed the warning caused by test_exec_no_namespace. The TypeChecker tests are not a concern because this is a deprecated feature that has already been dropped in the 3.0 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants