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

INTERNALERROR> TypeError: '<=' not supported between instances of 'int' and 'NoneType' #235

Open
voidus opened this issue Jul 11, 2024 · 2 comments

Comments

@voidus
Copy link
Contributor

voidus commented Jul 11, 2024

What is your setup and what steps did you do?
This is reduced from an issue I encountered in our project

> nix shell nixpkgs#python3

> which python
/nix/store/7hnr99nxrd2aw6lghybqdmkckq60j6l9-python3-3.11.9/bin/python

> find
.
./test_repro.py

> cat test_repro.py 
def test_hmm():
    method = "get"
    match method:
        case "post":

            def mk_request():
                return "a"
        case "get":

            def mk_request():
                return "b"
        case _:
            raise ValueError("Method must be either get or post")

    assert mk_request() == "yo"

> python -m venv env
python -m venv env  2,52s user 0,18s system 96% cpu 2,805 total

> . env/bin/activate
(env) > pip install pytest-testmon
Collecting pytest-testmon
  Using cached pytest_testmon-2.1.1-py3-none-any.whl.metadata (2.0 kB)
Collecting pytest<9,>=5 (from pytest-testmon)
  Using cached pytest-8.2.2-py3-none-any.whl.metadata (7.6 kB)
Collecting coverage<8,>=6 (from pytest-testmon)
  Using cached coverage-7.5.4-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (8.2 kB)
Collecting iniconfig (from pytest<9,>=5->pytest-testmon)
  Using cached iniconfig-2.0.0-py3-none-any.whl.metadata (2.6 kB)
Collecting packaging (from pytest<9,>=5->pytest-testmon)
  Using cached packaging-24.1-py3-none-any.whl.metadata (3.2 kB)
Collecting pluggy<2.0,>=1.5 (from pytest<9,>=5->pytest-testmon)
  Using cached pluggy-1.5.0-py3-none-any.whl.metadata (4.8 kB)
Using cached pytest_testmon-2.1.1-py3-none-any.whl (22 kB)
Using cached coverage-7.5.4-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236 kB)
Using cached pytest-8.2.2-py3-none-any.whl (339 kB)
Using cached pluggy-1.5.0-py3-none-any.whl (20 kB)
Using cached iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
Using cached packaging-24.1-py3-none-any.whl (53 kB)
Installing collected packages: pluggy, packaging, iniconfig, coverage, pytest, pytest-testmon
Successfully installed coverage-7.5.4 iniconfig-2.0.0 packaging-24.1 pluggy-1.5.0 pytest-8.2.2 pytest-testmon-2.1.1

[notice] A new release of pip is available: 24.0 -> 24.1.2
[notice] To update, run: pip install --upgrade pip

(env) > pip freeze                
coverage==7.5.4
iniconfig==2.0.0
packaging==24.1
pluggy==1.5.0
pytest==8.2.2
pytest-testmon==2.1.1


(env) > pytest --testmon          
/path/to/testmon_repro/env/lib/python3.11/site-packages/testmon/pytest_testmon.py:461: PytestRemovedIn9Warning: The (path: py.path.local) argument is deprecated, please use (collection_path: pathlib.Path)
see https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path
  def pytest_ignore_collect(self, path, config):
=========================================================================== test session starts ===========================================================================
platform linux -- Python 3.11.9, pytest-8.2.2, pluggy-1.5.0
testmon: new DB, environment: default
We'd like to hear from testmon users! 🙏🙏 go to https://testmon.org/survey to leave feedback ✅❌
rootdir: /path/to/testmon_repro
plugins: testmon-2.1.1
collected 1 item                                                                                                                                                          

test_repro.py F
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/main.py", line 285, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/main.py", line 339, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>     ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/logging.py", line 807, in pytest_runtestloop
INTERNALERROR>     return (yield)  # Run all the tests.
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/main.py", line 364, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 182, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_result.py", line 100, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     teardown.throw(outcome._exception)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/warnings.py", line 111, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     teardown.throw(outcome._exception)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/assertion/__init__.py", line 176, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     teardown.throw(outcome._exception)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/unittest.py", line 422, in pytest_runtest_protocol
INTERNALERROR>     res = yield
INTERNALERROR>           ^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     teardown.throw(outcome._exception)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/faulthandler.py", line 85, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/runner.py", line 116, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/runner.py", line 136, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "teardown", log, nextitem=nextitem))
INTERNALERROR>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/_pytest/runner.py", line 245, in call_and_report
INTERNALERROR>     ihook.pytest_runtest_logreport(report=report)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/testmon/pytest_testmon.py", line 373, in pytest_runtest_logreport
INTERNALERROR>     test_executions_fingerprints = self.testmon_data.get_tests_fingerprints(
INTERNALERROR>                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/testmon/testmon_core.py", line 216, in get_tests_fingerprints
INTERNALERROR>     fingerprint = create_fingerprint(module, covered)
INTERNALERROR>                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/path/to/testmon_repro/env/lib/python3.11/site-packages/testmon/process_code.py", line 280, in create_fingerprint
INTERNALERROR>     if sorted_lines[line_index] <= current_block.end:
INTERNALERROR>        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> TypeError: '<=' not supported between instances of 'int' and 'NoneType'

============================================================================ 1 failed in 0.04s ============================================================================

What was the outcome?
See above

What is your operating system and it's version please?
Reasonably updated arch linux with nix stuff generously sprinkled about...
I'm happy to help investigate if this doesn't reproduce as easily as I hope.

@voidus
Copy link
Contributor Author

voidus commented Jul 11, 2024

Maybe this is not a regression actually. I went back as far as pytest-testmon==1.2.3 and the error still occurs.

@robertschweizer
Copy link

We are also running into this issue, it is preventing us from using testmon now.

It seems to have something to do with defining functions inside match...case blocks:

import testmon.process_code

m = testmon.process_code.Module("""
def f(a):
    match a:
        case 23:
          def b():
              print("23")
        case 46:
          def b():
              print("46")
""")

[b.end for b in m.blocks]

prints [None, 9, 9, 9].

import testmon.process_code

m = testmon.process_code.Module("""
def f(a):
    if a == 23:
      def b():
          print("23")
    if a == 46:
      def b():
          print("46")
""")

[b.end for b in m.blocks]

prints [5, 8, 8, 8].

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