@@ -12,23 +12,43 @@ pip_ for installing your application and any dependencies,
12
12
as well as the ``pytest `` package itself.
13
13
This ensures your code and dependencies are isolated from your system Python installation.
14
14
15
- Next, place a ``setup.py `` file in the root of your package with the following minimum content :
15
+ Next, place a ``pyproject.toml `` file in the root of your package:
16
16
17
- .. code-block :: python
17
+ .. code-block :: toml
18
18
19
- from setuptools import setup, find_packages
19
+ [build-system]
20
+ requires = ["setuptools>=42", "wheel"]
21
+ build-backend = "setuptools.build_meta"
20
22
21
- setup( name = " PACKAGENAME " , packages = find_packages())
23
+ and a `` setup.cfg `` file containing your package's metadata with the following minimum content:
22
24
23
- Where ``PACKAGENAME `` is the name of your package. You can then install your package in "editable" mode by running from the same directory:
25
+ .. code-block :: ini
26
+
27
+ [metadata]
28
+ name = PACKAGENAME
29
+
30
+ [options]
31
+ packages = find:
32
+
33
+ where ``PACKAGENAME `` is the name of your package.
34
+
35
+ .. note ::
36
+
37
+ If your pip version is older than ``21.3 ``, you'll also need a ``setup.py `` file:
38
+
39
+ .. code-block :: python
40
+
41
+ from setuptools import setup
42
+
43
+ setup()
44
+
45
+ You can then install your package in "editable" mode by running from the same directory:
24
46
25
47
.. code-block :: bash
26
48
27
49
pip install -e .
28
50
29
51
which lets you change your source code (both tests and application) and rerun tests at will.
30
- This is similar to running ``python setup.py develop `` or ``conda develop `` in that it installs
31
- your package using a symlink to your development code.
32
52
33
53
.. _`test discovery` :
34
54
.. _`Python test discovery` :
@@ -68,7 +88,8 @@ to keep tests separate from actual application code (often a good idea):
68
88
69
89
.. code-block :: text
70
90
71
- setup.py
91
+ pyproject.toml
92
+ setup.cfg
72
93
mypkg/
73
94
__init__.py
74
95
app.py
@@ -82,7 +103,7 @@ This has the following benefits:
82
103
83
104
* Your tests can run against an installed version after executing ``pip install . ``.
84
105
* Your tests can run against the local copy with an editable install after executing ``pip install --editable . ``.
85
- * If you don't have a `` setup.py `` file and are relying on the fact that Python by default puts the current
106
+ * If you don't use an editable install and are relying on the fact that Python by default puts the current
86
107
directory in ``sys.path `` to import your package, you can execute ``python -m pytest `` to execute the tests against the
87
108
local copy directly, without using ``pip ``.
88
109
@@ -103,7 +124,8 @@ If you need to have test modules with the same name, you might add ``__init__.py
103
124
104
125
.. code-block :: text
105
126
106
- setup.py
127
+ pyproject.toml
128
+ setup.cfg
107
129
mypkg/
108
130
...
109
131
tests/
@@ -130,7 +152,8 @@ sub-directory of your root:
130
152
131
153
.. code-block :: text
132
154
133
- setup.py
155
+ pyproject.toml
156
+ setup.cfg
134
157
src/
135
158
mypkg/
136
159
__init__.py
@@ -167,7 +190,8 @@ want to distribute them along with your application:
167
190
168
191
.. code-block :: text
169
192
170
- setup.py
193
+ pyproject.toml
194
+ setup.cfg
171
195
mypkg/
172
196
__init__.py
173
197
app.py
@@ -191,11 +215,11 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
191
215
192
216
.. note ::
193
217
194
- You can use Python3 namespace packages (PEP420) for your application
218
+ You can use namespace packages (PEP420) for your application
195
219
but pytest will still perform `test package name `_ discovery based on the
196
220
presence of ``__init__.py `` files. If you use one of the
197
221
two recommended file system layouts above but leave away the ``__init__.py ``
198
- files from your directories it should just work on Python3.3 and above . From
222
+ files from your directories, it should just work. From
199
223
"inlined tests", however, you will need to use absolute imports for
200
224
getting at your application code.
201
225
@@ -230,8 +254,6 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
230
254
much less surprising.
231
255
232
256
233
- .. _`virtualenv` : https://pypi.org/project/virtualenv/
234
- .. _`buildout` : http://www.buildout.org/en/latest/
235
257
.. _pip : https://pypi.org/project/pip/
236
258
237
259
.. _`use tox` :
0 commit comments