obsidian_love/組織/EverfortuneAI/{Note} Nox.md

45 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
author: deng
date: "20250109"
category: Note
tags:
- Python
- Nox
- FlexibleTest
- Versioning
---
![cover](resources/nox.png)
[image resource](https://nox.thea.codes/en/stable/index.html)
- Abstract
- 在將Python專案打包時會遇到填寫依賴套件及其版本的問題開發者必須逐一測試Python版本與依賴套件版本之間甚至是跨平台不同組合的可運行性而Nox正是為了可以將此流程自動化而生
- Steps
1. 在虛擬環境中安裝Nox`pip install nox`
2. 在Package資料夾中產生*noxfile.py* 並撰寫測試程式碼範例程式碼可見Note
3. 於終端機輸入`nox` 開始進行測試
- Note
- 以下為*noxfile.py*範例程式碼(透過環境是否能順利執行單元測試來判別套件之間的匹配性)
```python
# noxfile.py
#
# author: deng
# date : 20250110
import nox
@nox.session(python=['3.10', '3.11', '3.12'])
@nox.parametrize('numpy', ['1.26', '2.0'])
@nox.parametrize('scikit_learn', ['1.5', '1.6'])
def test_flexibility(session, numpy, scikit_learn):
# Install package dependencies
session.install(f'numpy=={numpy}')
session.install(f'scikit-learn=={scikit_learn}')
# Test
session.install('pytest')
session.run('pytest')
```