Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use baked project for all tests #353

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
python -m pip install .[dev]
- name: Run pytest
run: |
python -m pytest -v
python -m pytest -v --durations=0
53 changes: 29 additions & 24 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def test_project_folder(cookies):

assert project.exit_code == 0
assert project.exception is None
assert project.project.basename == 'my-python-project'
assert project.project.isdir()
assert project.project_path.name == 'my-python-project'
assert project.project_path.is_dir()


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


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


@pytest.fixture
def baked_with_development_dependencies(cookies, project_env_bin_dir):
result = cookies.bake()
@pytest.fixture(scope='session')
def baked_with_development_dependencies(cookies_session, project_env_bin_dir):
result = cookies_session.bake()
assert result.exit_code == 0
bin_dir = project_env_bin_dir
latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], result.project)
latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], result.project_path)
assert latest_pip_output.returncode == 0
pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], result.project)
pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], result.project_path)
assert pip_output.returncode == 0
return result.project
return result.project_path


def test_pytest(baked_with_development_dependencies, project_env_bin_dir):
Expand Down Expand Up @@ -84,11 +85,11 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):
bin_dir = project_env_bin_dir
subpackage = (project_dir / 'my_python_package' / 'mysub')
subpackage.mkdir()
(subpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
(subpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")

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

# sdist and bdist_wheel both call build command to create build/ dir
# So instead of looking in distribution archives we can look in build/ dir
Expand Down Expand Up @@ -126,21 +127,25 @@ def test_coverage_api_docs(baked_with_development_dependencies, project_env_bin_
# 'Statistics',
# '----------',
# '',
# '+-----------------------------+----------+--------------+',
# '| Module | Coverage | Undocumented |',
# '+=============================+==========+==============+',
# '| my_python_package | 100.00% | 0 |',
# '+-----------------------------+----------+--------------+',
# '| my_python_package.my_module | 100.00% | 0 |',
# '+-----------------------------+----------+--------------+',
# '| TOTAL | 100.00% | 0 |',
# '+-----------------------------+----------+--------------+',
# '+--------------------------------+----------+--------------+',
# '| Module | Coverage | Undocumented |',
# '+================================+==========+==============+',
# '| my_python_package.my_module | 100.00% | 0 |',
# '+--------------------------------+----------+--------------+',
# '| my_python_package.mysub.mysub2 | 100.00% | 0 |',
# '+--------------------------------+----------+--------------+',
# '| my_python_package | 100.00% | 0 |',
# '+--------------------------------+----------+--------------+',
# '| my_python_package.mysub | 100.00% | 0 |',
# '+--------------------------------+----------+--------------+',
# '| TOTAL | 100.00% | 0 |',
# '+--------------------------------+----------+--------------+',
# ''
# ]
# The package coverage lines change order between runs, so we test for each data row individually:
assert '| my_python_package | 100.00% | 0 |' in coverage_file_lines
assert '| my_python_package.my_module | 100.00% | 0 |' in coverage_file_lines
assert '| TOTAL | 100.00% | 0 |' in coverage_file_lines
assert '| my_python_package | 100.00% | 0 |' in coverage_file_lines
assert '| my_python_package.my_module | 100.00% | 0 |' in coverage_file_lines
assert '| TOTAL | 100.00% | 0 |' in coverage_file_lines


def test_doctest_api_docs(baked_with_development_dependencies, project_env_bin_dir):
Expand Down