nvim-neotest / neotest-python

MIT License
116 stars 34 forks source link

pytest file opens on "assert" despite "JustMyCode" set to true. #58

Open chaudry-786 opened 8 months ago

chaudry-786 commented 8 months ago

Hello, my config is bare minimum and I only want my code debugged.

keymap("n", "<Leader>dt", ":lua require('neotest').run.run({strategy = 'dap'})<CR>", opts)
require("neotest").setup({
    adapters = {
        require("neotest-python")({
            dap = { justMyCode = true },
            python = venv_dir .. "python",
            runner = "pytest",
        })
    }
})

Take this test for example:

def test_addition():
    dic = {"name": "cat"}
    json.dumps(dic)
    assert 2 + 3 == 5

When I go past the line with "assert", then file "~/.local/share/nvim/lazy/neotest-python/neotest_python/pytest.py" and function "pytest_runtest_makereport" opens. I just want to debug my code. Interestingly if I try to "step in" at "json.dumps(dic)", I correctly get this message:

Note: may have been skipped because of "justMyCode" option (default == true).
wookayin commented 6 months ago

When I go past the line with "assert"

by doing this you get out of "my code". After this line where error is thrown out of your code, it is catched by the pytest framework.

{ justMyCode = true },

you want DAP to handle your code only.

So they conflict by definition?

istrupin commented 3 weeks ago

When I go past the line with "assert"

by doing this you get out of "my code". After this line where error is thrown out of your code, it is catched by the pytest framework.

{ justMyCode = true },

you want DAP to handle your code only.

So they conflict by definition?

I am inclined to agree with @chaudry-786 here in that the behavior was unexpected for me too. If justMyCode is set to true, I would expect the debugger to not put me into pytest, since pytest is library code, not my code. I'd expect to just have the behavior of the test passing or failing with the Note: may have been skipped because of "justMyCode" option (default == true). message displayed.