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")

EDIT:

This is the code for embedding Python in a C++ application: https://github.com/CEXT-Dan/PyRx/blob/9186472eb946f032f44c7963435e3299141e703e/PyRxCore/PyRxApp.cpp I don't know much about C++, so pasting a link is the only way I can do. The library itself is an extension module for CAD applications. To run the Python module, I simply call the PYLOAD command in the CAD application. Debugging is done using the remote attach in debugpy. After further analysis, however, I think it doesn't really matter. I think I need to write a hook for pytest that will request the execution (or collection) of tests from an external application. I already have code that runs tests remotely: https://github.com/CEXT-Dan/PyRx/blob/9186472eb946f032f44c7963435e3299141e703e/tests/runner.py - I just need to somehow connect it to pytest so that VScode can capture the results.

asked Nov 14, 2025 at 11:03
2
  • 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, 2025 at 2:00
  • @SergeyAKryukov, I added details Commented Nov 24, 2025 at 8:04

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.