0

I'm working on Python code that must be executed inside an external application which embeds its own Python interpreter (not the system Python, nor a virtual environment).
Because of this, I can't simply run the code with the standard Python extension in VS Code.

What I'd like to achieve is:

  • Write and maintain my Python code in VS Code

  • Run unit tests from the VS Code Test Explorer

  • Have the tests executed within the context of the external application by attaching VS Code to its embedded Python process (or something similar)

In other words, instead of VS Code spawning python to run tests, I want it to either:

  • Attach to the running external process,

  • Inject or execute the tests in its embedded Python interpreter

  • Run tests through some kind of custom test runner that forwards execution to the external application

Is this possible with VS Code?

If so, how can I configure the Python extension, debug adapter, or a custom test runner to make this work?

If not, is there any workaround or recommended approach for testing embedded-Python code from VS Code?

Any pointers, examples, or documentation would be greatly appreciated.

An example library providing an embedded interpreter: https://github.com/CEXT-Dan/PyRx

Code and test sample:

from pyrx import Db  # module provided by the application


def open_db(path: str) -> Db.Database:
    """Open a database from the given path."""
    db = Db.Database(False, True)
    db.readDwgFile(path)
    db.closeInput(True)
    return db
from pyrx import Db

def test_open_db():
    db = open_db("test_files/sample.dwg")
    assert isinstance(db, Db.Database)
    assert db.getFilename().endswith("sample.dwg")
1
  • Your samples are just some Python code, but the answer should depend on the code where Python is embedded. We don't know anything about this application and its debugging facility. Commented Nov 16 at 2:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.