If you're happy to compile all C++ source files present in the working directory in order to build your runnable, you should be able to just do
return_code = subprocess.run(f"g++ {cflags} -o prog *.cpp", shell=True)Is that all you need help with?
By the way ... the approach I've described uses a per-test template, which runs each test case separately. This means the same code gets compiled every time, and C++ compiles are relatively expensive. This isn't likely to be a problem with assignment questions but in a test/exam situation is best avoided as it puts unnecessary load on the Jobe servers. You can avoid the problem by using a combinator template that first compiles the code and then proceeds to run all tests if and only if the compile succeeds. However, combinator templates are much harder to write, as you have to build your own test results table.