diff --git a/.obsidian/workspace-mobile.json b/.obsidian/workspace-mobile.json index 5326b37..aa3de26 100644 --- a/.obsidian/workspace-mobile.json +++ b/.obsidian/workspace-mobile.json @@ -147,6 +147,7 @@ "active": "e0251782d53c0c60", "lastOpenFiles": [ "組織/EverfortuneAI/{Note} Packaging Python Project.md", + "組織/EverfortuneAI/{Note} Nox.md", "README.md", "Test.md", "組織/EverfortuneAI/resources/should_setup_py_be_deleted.png", diff --git a/組織/EverfortuneAI/{Note} Nox.md b/組織/EverfortuneAI/{Note} Nox.md index 34ab74b..b4e6017 100644 --- a/組織/EverfortuneAI/{Note} Nox.md +++ b/組織/EverfortuneAI/{Note} Nox.md @@ -13,12 +13,15 @@ tags: [image resource](https://nox.thea.codes/en/stable/index.html) - Abstract - - 在將Python專案打包時會遇到填寫依賴套件及其版本的問題,開發者必須逐一測試Python版本與依賴套件版本之間(甚至是跨平台)不同組合的可運行性,而Nox正是為了可以將此流程自動化而生 + - 在將Python專案打包時會遇到填寫依賴套件及其版本的問題,開發者必須逐一測試Python版本與依賴套件版本之間(甚至是跨平台)不同組合的可運行性,而Nox可以將這一流程自動化 - Steps - 1. 在虛擬環境中安裝Nox(`pip install nox`) + 1. 在開發環境中安裝Nox(`python -m pip install nox`) 2. 在Package資料夾中產生*noxfile.py* 並撰寫測試程式碼(範例程式碼可見Note) 3. 於終端機輸入`nox` 開始進行測試 - Note + - 若只想執行某個函式的程式碼,可執行`nox -s [function_name]` + - 若想將測試結果輸出檔案,可執行`nox --report [file_name].json` + - 小知識,如果semantic version沒有給patch的話,則其為0(比方說我們要測試的numpy版本設為1.24,則其實際測試的版本為1.24.0) - 以下為*noxfile.py*範例程式碼(透過環境是否能順利通過單元測試來判別套件之間的匹配性) ```python @@ -30,7 +33,7 @@ tags: import nox -@nox.session(python=['3.10', '3.11', '3.12']) +@nox.session(venv_backend='conda', 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): @@ -41,5 +44,5 @@ def test_flexibility(session, numpy, scikit_learn): # Test session.install('pytest') - session.run('pytest') + session.run('pytest', 'tests', '-v') ``` \ No newline at end of file