File: pytest_runner.cpp

package info (click to toggle)
python-ppmd 0.5.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,636 kB
  • sloc: ansic: 2,574; python: 870; cpp: 23; makefile: 21; sh: 2
file content (25 lines) | stat: -rw-r--r-- 646 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <string>
#include <Python.h>

int main(int argc, char **argv) {
    std::string args;
    if ( argc > 1) {
        args.append("[");
        for (int i = 1; i < argc; i++) {
            if (i > 2)
                args.append(",");
            args.append("\"");
            args.append(argv[i]);
            args.append("\"");
        }
        args.append("]");
    }
    std::string pycode = "import pytest\npytest.main(" + args + ")\n";
    wchar_t * program_name = Py_DecodeLocale(argv[0], NULL);
    Py_SetProgramName(program_name);
    Py_Initialize();
    PyRun_SimpleString(&*pycode.begin());
    Py_Finalize();
    return 0;
}