Testing Python remote plugin?

Hello everyone,

I have recently written a little remote plugin in Python: pycodestyle.nvim. I would like to add some tests to it using Pytest, but I cannot figure out how to set up the project structure. I tried the following two:

├── rplugin
│   └── python3
│       ├── pycodestyle_nvim
│       │   └── test
│       │       ├── conftest.py
│       │       └── test_main.py
│       └── pycodestyle_nvim.py
└── setup.cfg

├── rplugin
│   └── python3
│       ├── __init__.py
│       ├── pycodestyle_nvim
│       └── pycodestyle_nvim.py
├── setup.cfg
└── test
    ├── conftest.py
    └── test_main.py

Both have the same problem: I cannot import the plugin module. Here is my simple toy test:

import pytest
from pynvim import Nvim  # type:ignore
from rplugin.python3.pycodestyle_nvim import NvimPycodestyle


class FakeNvim(Nvim):
    """Fake Neovim implementation"""
    pass


@pytest.fixture
def nvim() -> Nvim:
    return FakeNvim()


@pytest.fixture
def sut(nvim: Nvim) -> NvimPycodestyle:
    return NvimPycodestyle(nvim)


def test_nothing_found(sut: NvimPycodestyle):
    print(sut)
    pass

When I try running the test I get this error:

=============================================== test session starts ================================================
platform linux -- Python 3.9.7, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/hiphish/Developer/vim/pycodestyle.nvim
collected 0 items / 1 error

====================================================== ERRORS ======================================================
_______________________ ERROR collecting rplugin/python3/pycodestyle_nvim/test/test_main.py ________________________
ImportError while importing test module '/home/hiphish/Developer/vim/pycodestyle.nvim/rplugin/python3/pycodestyle_nv
im/test/test_main.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
rplugin/python3/pycodestyle_nvim/test/test_main.py:2: in <module>
    from rplugin.python3.pycodestyle_nvim import NvimPycodestyle
E   ModuleNotFoundError: No module named 'rplugin'
================================================= warnings summary =================================================
../../../.local/lib/python3.9/site-packages/pynvim/compat.py:5
  /home/hiphish/.local/lib/python3.9/site-packages/pynvim/compat.py:5: DeprecationWarning: the imp module is depreca
ted in favour of importlib; see the module's documentation for alternative uses
    from imp import find_module as original_find_module

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================= short test summary info ==============================================
ERROR rplugin/python3/pycodestyle_nvim/test/test_main.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=========================================== 1 warning, 1 error in 0.07s ============================================

I am aware that testing such a simple plugin is probably overkill, but it makes for a good minimal example before trying my hands on a bigger plugin. The question is, how do I need to set up my directory structure so the plugin is testable, and test scripts don’t step onto some other plugins’ toes.