mfussenegger / nvim-dap-python

An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: test_method issues wrong test path for tests with >1 level of nesting

fnune opened this issue · comments

Hi!

Here's my keybinding:

vim.api.nvim_set_keymap('n', '<leader>ds', ':lua require("dap-python").test_method()<CR>', { noremap = true, silent = true })

Top-level test

If I run it on a test like this, it works fine:

def test_a():
  assert True

Issues path::test_a correctly

Nested (n=1) test

class TestB:
  def test_b(self):
    assert True

Issues path::TestB::test_b correctly

Nested (n>1) test

class TestC:
  class TestC1:
    def test_c(self):
      assert True

Issues path::TestC::test_c incorrectly: notice the missing ::TestC1

Expected vs actual

- path::TestC::TestC1::test_c
+ path::TestC::test_c

Error reads:

ERROR: not found: path::TestC::test_c
(no name 'path::TestC::test_c' in any of [<Module path>])

I have an issue that is possibly related, also involving nested paths.

If I have files like this, then pytest from the command line will run and pass, but with the runner in nvim-dap will not be able to find the correct method.

class TestConverter(object):
    def test_something(self, monkeypatch): 
        def mock_something(msg):
            return "AAAA"
        monkeypatch.setattr(Converter, "something", mock_something)
        converter = Converter()
        assert converter.to_shout() == "AAAA"

class Converter(object):
    def something(self, msg):
        return msg.upper()

The error message is similar:

ERROR: not found: /tmp/testnest/tests/test_conv.py::Converter::something
(no name '/tmp/testnest/tests/test_main.py::Converter::something' in any of [<Module tests/test_conv.py>])