test.cpp 486 B

123456789101112131415161718192021
  1. #include "test.h"
  2. #include <Python.h>
  3. #include <library/cpp/testing/unittest/registar.h>
  4. TTestPyInvoker::TTestPyInvoker() {}
  5. const char* TTestPyInvoker::GetVersion() {
  6. Py_Initialize();
  7. auto* module = PyImport_ImportModule("sys");
  8. UNIT_ASSERT(module != nullptr);
  9. auto* versionObj = PyObject_GetAttrString(module, "version");
  10. if (versionObj == nullptr) {
  11. Py_DECREF(module);
  12. UNIT_ASSERT(versionObj != nullptr);
  13. }
  14. return Py_GetVersion();
  15. }