Skip to content

Commit d427e08

Browse files
committed
Fix: clarify the section on adding tests to src layout
1 parent 45b7ff8 commit d427e08

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

package-structure-code/python-package-structure.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ for new maintainers. It is also recommended in the
5757
makes it easier for you to create a package build workflow that tests your
5858
package as it will be installed on a users computer.
5959

60-
The key characteristic of this layout is that your package
61-
uses a **src/package-name** directory structure. With this layout it is also
62-
common to include your `tests/` directory outside of the package
63-
directory.
60+
The key characteristics of this layout include:
61+
62+
- Your package uses a **src/package-name** directory structure,
63+
- You include a `tests/` directory outside of the package
64+
directory.
6465

6566
```{admonition} Example scientific packages that use **src/package-name** layout
6667
@@ -90,15 +91,33 @@ The benefits of the **src/package-name** layout include:
9091
package rather than on the flat files imported directly from your package. If you run your tests on your flat files, you may be missing issues that users encounter when your package is installed.
9192
- If `tests/` are outside of the **src/package-name** directory, they aren't by default
9293
delivered to a user
93-
installing your package. However, you can chose to add them to the package archive (which is a good idea). When test files (.py files only) are not included in the package archive your package size will be slightly smaller.
94+
installing your package. When test files (.py files only) are not included in the package wheel your package size will be slightly smaller. This places a smaller storage burden on PyPI which has over 400,000 packages to support.
9495

95-
```{admonition} A note about including tests and data in your package distribution
96-
If you decide to include tests in your package, be sure to read the [pytest documentation](https://docs.pytest.org/en/7.2.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules).
96+
````{admonition} A note about including tests and data in your package distribution
97+
If you decide to include tests in your package, your directory structure
98+
will look like the example below. Notice that below the tests directory
99+
is contained within the src/package-name directory ensuring the tests will be included in your package's wheel.
97100
98-
Also check out the testing section of our guide. Large datasets associated with tests will slow down your package's install which can be frustrating to users. It also will consume more storage space on PyPI which is largely supported by volunteer maintainers and has storage costs to consider for it's 400,000+ packages. As such you
99-
will want to ensure that large tests datasets are not included in your package distribution.
101+
```bash
102+
src/
103+
package-name/
104+
tests/
105+
docs/
100106
```
101107
108+
Be sure to read the [pytest documentation](https://docs.pytest.org/en/7.2.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules).
109+
110+
### **Don't include test suite datasets in your package**
111+
112+
Large datasets associated with tests will slow down your package's install which can be frustrating to users. It also will consume more storage space on PyPI which is largely supported by volunteer maintainers and has storage costs to consider for it's 400,000+ packages.
113+
114+
As such you
115+
should never include datasets needed for your tests in your package
116+
distribution. Rather consider hosting them on a data repository such as figshare or zenodo and using a tool such as [Pooch](https://www.fatiando.org/pooch/latest/) to access them when you run tests.
117+
Check out the testing section of our guide for more information about tests.
118+
119+
````
120+
102121
- The **src/package-name** layout is semantically more clear. Code is always found in the
103122
**src/package-name** directory, `tests/` and `docs/`are in the root directory.
104123

0 commit comments

Comments
 (0)