nvim-neotest / neotest-python

MIT License
137 stars 40 forks source link

No tests found in file #52

Closed Zeioth closed 1 year ago

Zeioth commented 1 year ago

I have the program

import helper

helper.hello_world()

And the pytest test:

import helper

def test_hello_world(capsys):
    # Capture stdout using capsys
    helper.hello_world()
    captured = capsys.readouterr()

    # Check if the expected output is present in captured stdoutrequire("neotest").run.run({strategy = "dap"})
    expected_output = "Hello, World!"
    assert expected_output in captured.out

But when I open the test file, and run lua require("neotest").run.run() I get No tests found

screenshot_2023-08-12_19-45-03_108533332

I have pytest installed on my machine. What I'm missing?

My neotest config is

      require("neotest").setup {
        adapters = {
          require "neotest-python",
        },
      }
    end,
    dependencies = {
      "nvim-neotest/neotest-python",
    },

EDIT: I forgot to mention I can run pytest on my project directory, and that runs the test correctly.

Zeioth commented 1 year ago

After checking here

I've tried to run lua print(require("neotest-python").is_test_file(vim.fn.expand("%:p")))

And it returns true on my file helper_test.py but it still returns No test found

Zeioth commented 1 year ago

Apologies, it works correctly with this neotest config:

  {
    "nvim-neotest/neotest",
    ft = { "go", "rust", "python", "cs", "typescript", "javascript" },
    dependencies = {
      "nvim-neotest/neotest-go",
      "nvim-neotest/neotest-python",
      "rouge8/neotest-rust",
      "Issafalcon/neotest-dotnet",
      "nvim-neotest/neotest-jest",
    },
    opts = function()
      return {
        -- your neotest config here
        adapters = {
          require "neotest-dotnet",
          require "neotest-python",
          require "neotest-rust",
          require "neotest-go",
          require "neotest-jest",
        },
      }
    end,
    config = function(_, opts)
      -- get neotest namespace (api call creates or returns namespace)
      local neotest_ns = vim.api.nvim_create_namespace "neotest"
      vim.diagnostic.config({
        virtual_text = {
          format = function(diagnostic)
            local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
            return message
          end,
        },
      }, neotest_ns)
      require("neotest").setup(opts)
    end,
  },

Closing.