Skip to content

Commit b8299c1

Browse files
committed
Using py::embed instead of CPython C API
1 parent 7f96473 commit b8299c1

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

test/downloadGTest.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ project(googletest-download NONE)
1313
include(ExternalProject)
1414
ExternalProject_Add(googletest
1515
GIT_REPOSITORY https://github.com/google/googletest.git
16-
GIT_TAG release-1.8.0
16+
GIT_TAG release-1.8.1
1717
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
1818
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
1919
CONFIGURE_COMMAND ""

test/main.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,29 @@
66
* The full license is in the file LICENSE, distributed with this software. *
77
****************************************************************************/
88

9-
// Required to avoid the error "std does not have memeber copysign"
9+
// Required to avoid the error "std does not have member copysign"
1010
#include <cmath>
11-
#include <Python.h>
1211

13-
#include "pybind11/numpy.h"
12+
#include "gtest/gtest.h"
13+
14+
#include <pybind11/embed.h>
1415

1516
#define FORCE_IMPORT_ARRAY
1617
#include "xtensor-python/pyarray.hpp"
1718

18-
#include "gtest/gtest.h"
19-
#include <iostream>
19+
namespace py = pybind11;
2020

2121
int main(int argc, char* argv[])
2222
{
23-
// Initialize all the things (google-test and Python interpreter)
24-
Py_Initialize();
23+
// Initialize all the things (Python, numpy, gtest)
24+
py::scoped_interpreter guard{};
2525
xt::import_numpy();
2626
::testing::InitGoogleTest(&argc, argv);
2727

2828
// Run test suite
2929
int ret = RUN_ALL_TESTS();
3030

31-
// Closure of the Python interpreter
32-
Py_Finalize();
31+
// Return test results
3332
return ret;
3433
}
3534

0 commit comments

Comments
 (0)