Skip to content

Commit f9d0fcb

Browse files
Integrate tests into CI
1 parent 87e0e2e commit f9d0fcb

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
python:
1818
name: Build g2opy
1919
runs-on: ubuntu-latest
20+
env:
21+
G2O_CACHE_BUILD: true
2022
steps:
2123
- uses: actions/checkout@v4
2224
with:
@@ -27,6 +29,8 @@ jobs:
2729
sudo apt install libeigen3-dev libspdlog-dev nlohmann-json3-dev
2830
- name: Build
2931
run: pipx run build
32+
- name: Run tests
33+
run: /tmp/g2opy/pytest_helper.sh
3034

3135
build:
3236
name: ${{ matrix.config.name }}

python/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ target_link_libraries(g2opy PRIVATE
7777
)
7878
target_include_directories(g2opy PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
7979
install(TARGETS g2opy LIBRARY DESTINATION g2opy)
80+
81+
#Write pytest helper script to build folder
82+
file(WRITE "${CMAKE_BINARY_DIR}/pytest_helper.sh" "#!/bin/sh
83+
set -e
84+
export G2O_LIB_DIR=\"${g2o_LIBRARY_OUTPUT_DIRECTORY}\"
85+
exec pytest \"${CMAKE_CURRENT_SOURCE_DIR}\"
86+
")
87+
file(CHMOD "${CMAKE_BINARY_DIR}/pytest_helper.sh" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)

pytest.ini renamed to python/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
testpaths = python/tests
2+
testpaths = tests
33
python_files = test_*.py
44
python_classes = Test*
55
python_functions = test_*

python/tests/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Pytest fixtures for g2o Python bindings tests."""
22

3+
import os
34
import sys
45
import tempfile
56
from pathlib import Path
67

7-
# Ensure build lib is in path BEFORE any imports - this is critical
8-
build_lib_path = Path(__file__).resolve().parent.parent.parent / "build" / "lib"
9-
build_lib_str = str(build_lib_path)
10-
if build_lib_str not in sys.path:
11-
sys.path.insert(0, build_lib_str)
8+
# Ensure build lib is in path BEFORE any imports
9+
build_lib_dir = os.environ.get(
10+
"G2O_LIB_DIR", str(Path(__file__).resolve().parent.parent.parent / "build" / "lib")
11+
)
12+
sys.path.insert(0, build_lib_dir)
1213

1314
# This must come after path setup
1415
import g2opy as g2o

0 commit comments

Comments
 (0)