Skip to content

Commit 795794e

Browse files
authored
Merge pull request #353 from NLeSC/speedup-tests
Re-use baked project for all tests
2 parents ebc67dd + c449192 commit 795794e

2 files changed

Lines changed: 30 additions & 25 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
python -m pip install .[dev]
3535
- name: Run pytest
3636
run: |
37-
python -m pytest -v
37+
python -m pytest -v --durations=0

tests/test_project.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def test_project_folder(cookies):
1414

1515
assert project.exit_code == 0
1616
assert project.exception is None
17-
assert project.project.basename == 'my-python-project'
18-
assert project.project.isdir()
17+
assert project.project_path.name == 'my-python-project'
18+
assert project.project_path.is_dir()
1919

2020

2121
def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProcess:
@@ -29,8 +29,9 @@ def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProces
2929
return completed_process
3030

3131

32-
@pytest.fixture
33-
def project_env_bin_dir(tmp_path):
32+
@pytest.fixture(scope='session')
33+
def project_env_bin_dir(tmp_path_factory):
34+
tmp_path = tmp_path_factory.mktemp('venv')
3435
env_output = run(['python', '-m', 'venv', 'env'], tmp_path)
3536
assert env_output.returncode == 0
3637
bin_dir = str(tmp_path / 'env' / 'bin')
@@ -39,16 +40,16 @@ def project_env_bin_dir(tmp_path):
3940
return str(bin_dir) + os.sep
4041

4142

42-
@pytest.fixture
43-
def baked_with_development_dependencies(cookies, project_env_bin_dir):
44-
result = cookies.bake()
43+
@pytest.fixture(scope='session')
44+
def baked_with_development_dependencies(cookies_session, project_env_bin_dir):
45+
result = cookies_session.bake()
4546
assert result.exit_code == 0
4647
bin_dir = project_env_bin_dir
47-
latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], result.project)
48+
latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], result.project_path)
4849
assert latest_pip_output.returncode == 0
49-
pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], result.project)
50+
pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], result.project_path)
5051
assert pip_output.returncode == 0
51-
return result.project
52+
return result.project_path
5253

5354

5455
def test_pytest(baked_with_development_dependencies, project_env_bin_dir):
@@ -84,11 +85,11 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):
8485
bin_dir = project_env_bin_dir
8586
subpackage = (project_dir / 'my_python_package' / 'mysub')
8687
subpackage.mkdir()
87-
(subpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
88+
(subpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")
8889

8990
subsubpackage = (project_dir / 'my_python_package' / 'mysub' / 'mysub2')
9091
subsubpackage.mkdir()
91-
(subsubpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
92+
(subsubpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")
9293

9394
# sdist and bdist_wheel both call build command to create build/ dir
9495
# So instead of looking in distribution archives we can look in build/ dir
@@ -126,21 +127,25 @@ def test_coverage_api_docs(baked_with_development_dependencies, project_env_bin_
126127
# 'Statistics',
127128
# '----------',
128129
# '',
129-
# '+-----------------------------+----------+--------------+',
130-
# '| Module | Coverage | Undocumented |',
131-
# '+=============================+==========+==============+',
132-
# '| my_python_package | 100.00% | 0 |',
133-
# '+-----------------------------+----------+--------------+',
134-
# '| my_python_package.my_module | 100.00% | 0 |',
135-
# '+-----------------------------+----------+--------------+',
136-
# '| TOTAL | 100.00% | 0 |',
137-
# '+-----------------------------+----------+--------------+',
130+
# '+--------------------------------+----------+--------------+',
131+
# '| Module | Coverage | Undocumented |',
132+
# '+================================+==========+==============+',
133+
# '| my_python_package.my_module | 100.00% | 0 |',
134+
# '+--------------------------------+----------+--------------+',
135+
# '| my_python_package.mysub.mysub2 | 100.00% | 0 |',
136+
# '+--------------------------------+----------+--------------+',
137+
# '| my_python_package | 100.00% | 0 |',
138+
# '+--------------------------------+----------+--------------+',
139+
# '| my_python_package.mysub | 100.00% | 0 |',
140+
# '+--------------------------------+----------+--------------+',
141+
# '| TOTAL | 100.00% | 0 |',
142+
# '+--------------------------------+----------+--------------+',
138143
# ''
139144
# ]
140145
# The package coverage lines change order between runs, so we test for each data row individually:
141-
assert '| my_python_package | 100.00% | 0 |' in coverage_file_lines
142-
assert '| my_python_package.my_module | 100.00% | 0 |' in coverage_file_lines
143-
assert '| TOTAL | 100.00% | 0 |' in coverage_file_lines
146+
assert '| my_python_package | 100.00% | 0 |' in coverage_file_lines
147+
assert '| my_python_package.my_module | 100.00% | 0 |' in coverage_file_lines
148+
assert '| TOTAL | 100.00% | 0 |' in coverage_file_lines
144149

145150

146151
def test_doctest_api_docs(baked_with_development_dependencies, project_env_bin_dir):

0 commit comments

Comments
 (0)