11import os
22import subprocess
3- from sys import platform
3+ from pathlib import Path
4+ from sys import platform , executable
45from typing import Sequence
56
67import pytest
@@ -17,10 +18,10 @@ def test_project_folder(cookies):
1718
1819def run (args : Sequence [str ], dirpath : os .PathLike ) -> subprocess .CompletedProcess :
1920 completed_process = subprocess .run (args = args ,
20- stdout = subprocess .PIPE ,
21- stderr = subprocess .PIPE ,
22- cwd = dirpath ,
23- encoding = "utf-8" )
21+ stdout = subprocess .PIPE ,
22+ stderr = subprocess .PIPE ,
23+ cwd = dirpath ,
24+ encoding = "utf-8" )
2425 print (completed_process .stdout )
2526 print (completed_process .stderr )
2627 return completed_process
@@ -29,27 +30,32 @@ def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProces
2930@pytest .fixture
3031def baked_with_development_dependencies (cookies ):
3132 result = cookies .bake ()
32- env_output = run (['python3' , '-m' , 'venv' , 'env' ], result .project )
33- assert env_output .returncode == 0
34- env_bin = 'env/Scripts/' if platform .startswith ("win" ) else 'env/bin/'
35- latest_pip_output = run ([f'{ env_bin } pip3' , 'install' , '--upgrade' , 'pip' , 'setuptools' ], result .project )
33+ if platform .startswith ("win" ) and os .environ .get ('CI' , False ):
34+ # Creating virtualenv does not work on Windows CI,
35+ # falling back to using current Python
36+ bin_dir = str (Path (executable ).parent ) + '\\ '
37+ else :
38+ env_output = run (['python3' , '-m' , 'venv' , 'env' ], result .project )
39+ assert env_output .returncode == 0
40+ bin_dir = 'env/Scripts/' if platform .startswith ("win" ) else 'env/bin/'
41+ latest_pip_output = run ([f'{ bin_dir } pip3' , 'install' , '--upgrade' , 'pip' , 'setuptools' ], result .project )
3642 assert latest_pip_output .returncode == 0
37- pip_output = run ([f'{ env_bin } pip3' , 'install' , '--editable' , '.[dev]' ], result .project )
43+ pip_output = run ([f'{ bin_dir } pip3' , 'install' , '--editable' , '.[dev]' ], result .project )
3844 assert pip_output .returncode == 0
39- return result .project , env_bin
45+ return result .project , bin_dir
4046
4147
4248def test_pytest (baked_with_development_dependencies ):
43- project_dir , env_bin = baked_with_development_dependencies
44- pytest_output = run ([f'{ env_bin } pytest' ], project_dir )
49+ project_dir , bin_dir = baked_with_development_dependencies
50+ pytest_output = run ([f'{ bin_dir } pytest' ], project_dir )
4551 assert pytest_output .returncode == 0
4652 assert '== 3 passed in' in pytest_output .stdout
4753 assert (project_dir / 'coverage.xml' ).exists ()
4854 assert (project_dir / 'htmlcov/index.html' ).exists ()
4955
5056
5157def test_subpackage (baked_with_development_dependencies ):
52- project_dir , env_bin = baked_with_development_dependencies
58+ project_dir , bin_dir = baked_with_development_dependencies
5359 subpackage = (project_dir / 'my_python_package' / 'mysub' )
5460 subpackage .mkdir ()
5561 (subpackage / '__init__.py' ).write_text ('FOO = "bar"' , encoding = "utf-8" )
@@ -58,15 +64,16 @@ def test_subpackage(baked_with_development_dependencies):
5864 subsubpackage .mkdir ()
5965 (subsubpackage / '__init__.py' ).write_text ('FOO = "bar"' , encoding = "utf-8" )
6066
61- build_output = run ([f'{ env_bin } python' , 'setup.py' , 'build' ], project_dir )
67+ build_output = run ([f'{ bin_dir } python' , 'setup.py' , 'build' ], project_dir )
6268 assert build_output .returncode == 0
6369 assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / '__init__.py' ).exists ()
6470 assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / 'mysub2' / '__init__.py' ).exists ()
6571
6672
6773def test_generate_api_docs (baked_with_development_dependencies ):
68- project_dir , env_bin = baked_with_development_dependencies
74+ project_dir , bin_dir = baked_with_development_dependencies
6975
70- build_output = run ([f'{ env_bin } sphinx-build' , '-b' , 'html' , 'docs' , 'docs/_build/html' ], project_dir )
76+ build_output = run ([f'{ bin_dir } sphinx-build' , '-b' , 'html' , 'docs' , 'docs/_build/html' ], project_dir )
7177 assert build_output .returncode == 0
78+ assert 'build succeeded' in build_output .stdout
7279 assert (project_dir / 'docs' / '_build' / 'html' / 'index.html' ).exists ()
0 commit comments