Skip to content

Commit

Permalink
Pytest skeleton in mixed template
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-werner committed Oct 17, 2023
1 parent 2536fff commit b2d574d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Add unittest skeleton to mixed Python/Rust projects

## [1.3.0] - 2023-10-02

* Refactor Cargo sdist generator to avoid rewriting local dependencies in [#1741](https://github.com/PyO3/maturin/pull/1741)
Expand Down
5 changes: 5 additions & 0 deletions src/new_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl<'a> ProjectGenerator<'a> {
env.add_template("main.rs", include_str!("templates/main.rs.j2"))?;
env.add_template("build.rs", include_str!("templates/build.rs.j2"))?;
env.add_template("__init__.py", include_str!("templates/__init__.py.j2"))?;
env.add_template("test_all.py", include_str!("templates/test_all.py.j2"))?;
env.add_template("example.udl", include_str!("templates/example.udl.j2"))?;

let bridge_model = match bindings.as_str() {
Expand Down Expand Up @@ -86,6 +87,10 @@ impl<'a> ProjectGenerator<'a> {
fs::create_dir_all(&python_project)?;
self.write_project_file(&python_project, "__init__.py")?;

let test_dir = python_dir.join("tests");
fs::create_dir_all(&test_dir)?;
self.write_project_file(&test_dir, "test_all.py")?;

if src {
project_path.join("rust")
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/templates/pyproject.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ classifiers = [
{% if bindings == "cffi" -%}
dependencies = ["cffi"]
{% endif -%}
{% if mixed_non_src -%}
[project.optional-dependencies]
tests = [
"pytest",
]
{% endif -%}
dynamic = ["version"]

{% if bindings in ["bin", "cffi", "pyo3", "rust-cpython"] or mixed_non_src -%}
Expand Down
5 changes: 5 additions & 0 deletions src/templates/test_all.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest
import {{ crate_name }}

def test_nothing():
assert True

0 comments on commit b2d574d

Please sign in to comment.