Skip to content

Commit

Permalink
Force Python 3.11 all over, make pytest absence an error when testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lgeretti committed Nov 2, 2023
1 parent 77f51cb commit 0255057
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Get Concurrency
run: echo NPROC="nproc" >> $GITHUB_ENV

- name: Set Up Dependencies
run: |
sudo apt install -y cmake ninja-build pkg-config lcov g++-11 libcairo2-dev gnuplot libmpfr-dev python3-pip python3-dev gnuplot
sudo apt install -y cmake ninja-build pkg-config lcov g++-11 libcairo2-dev gnuplot libmpfr-dev python3-pip python3.11-dev gnuplot
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
sudo pip3 install coverage pytest
- name: Create Build Environment
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Get macOS Concurrency
if: runner.os == 'macOS'
Expand All @@ -57,15 +60,16 @@ jobs:
- name: Set Up macOS Dependencies
if: runner.os == 'macOS'
run: |
brew install ninja gcc@12 python3 mpfr cairo gnuplot pkg-config
brew install ninja gcc@12 mpfr cairo gnuplot pkg-config
python3 -m pip install --upgrade pip
pip3 install --upgrade pip
pip3 install pytest
- name: Set Up Linux Dependencies
if: runner.os == 'Linux'
run: |
sudo apt install -y cmake ninja-build pkg-config clang-15 g++-12 libcairo2-dev gnuplot libmpfr-dev python3-pip python3-dev
sudo apt install -y cmake ninja-build pkg-config clang-15 g++-12 libcairo2-dev gnuplot libmpfr-dev python3-pip python3.11-dev
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
sudo pip3 install pytest
- name: Create Build Environment
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Get macOS Concurrency
if: runner.os == 'macOS'
Expand All @@ -72,7 +75,9 @@ jobs:
- name: Set Up Linux Dependencies
if: runner.os == 'Linux'
run: |
sudo apt install -y cmake ninja-build pkg-config ${{matrix.config.cxx-pkg}} libcairo2-dev gnuplot libmpfr-dev python3-pip python3-dev
sudo apt install -y cmake ninja-build pkg-config ${{matrix.config.cxx-pkg}} libcairo2-dev gnuplot libmpfr-dev python3-pip python3.11-dev
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
sudo pip3 install pytest
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand Down
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Python3 COMPONENTS Interpreter Development)
find_package(Python3 3.11 EXACT COMPONENTS Interpreter Development)

if(PYTHON3_FOUND)

Expand Down
12 changes: 8 additions & 4 deletions python/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
execute_process(COMMAND ${Python3_EXECUTABLE} -m pytest --version RESULT_VARIABLE PYTEST_result OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND pytest --version RESULT_VARIABLE PYTEST_result OUTPUT_QUIET ERROR_QUIET)
if(${PYTEST_result} EQUAL 0)
set(PYTHON_TESTS ON)
message(STATUS "pytest package found, Python tests will be performed.")
else()
message(WARNING "pytest package not available, will not perform Python tests.")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "pytest package not available, can not perform Python tests.")
else()
message(WARNING "pytest package not available, will not perform Python tests.")
endif()
endif()

if(PYTHON_TESTS)
Expand All @@ -20,8 +24,8 @@ if(PYTHON_TESTS)
)

foreach(TESTNAME ${TESTS_PYTHON})
add_custom_target(test_python_${TESTNAME} COMMAND ${Python3_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/test_${TESTNAME}.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME test_python_${TESTNAME} COMMAND ${Python3_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/test_${TESTNAME}.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(test_python_${TESTNAME} COMMAND pytest ${CMAKE_CURRENT_SOURCE_DIR}/test_${TESTNAME}.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME test_python_${TESTNAME} COMMAND pytest ${CMAKE_CURRENT_SOURCE_DIR}/test_${TESTNAME}.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_property(TEST test_python_${TESTNAME} PROPERTY ENVIRONMENT "PYTHONPATH=${PROJECT_BINARY_DIR}/python")
set_property(TEST test_python_${TESTNAME} PROPERTY LABELS "python")
endforeach()
Expand Down

0 comments on commit 0255057

Please sign in to comment.