Skip to content

Commit b7ff1e5

Browse files
author
Takashi Matsuo
authored
docs: Add few examples for uuid. (#3551)
1 parent 06a8848 commit b7ff1e5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

AUTHORING_GUIDE.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ for system testing, as shown in [this
285285
example](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/localtesting/datastore_test.py).
286286
* All tests should be independent of one another and order-independent.
287287
* We use parallel processing for tests, so tests should be capable of running in parallel with one another.
288+
* Use pytest's fixture for resource setup and teardown, instead of
289+
having them in the test itself.
288290

289291
### Arrange, Act, Assert
290292

@@ -320,10 +322,22 @@ that embodies assumptions about the behavior of the APIs.
320322
When tests need temporary resources (such as a temp file or folder), they
321323
should create reasonable names for these resources with a UUID attached to
322324
assure uniqueness. Use the Python ```uuid``` package from the standard
323-
library to generate UUIDs for resource names.
325+
library to generate UUIDs for resource names. For example:
324326

325-
All temporary resources should be explicitly deleted when
326-
testing is complete.
327+
```python
328+
glossary_id = 'test-glossary-{}'.format(uuid.uuid4())
329+
```
330+
331+
or:
332+
333+
```python
334+
# If full uuid4 is too long, use hex representation.
335+
encrypted_disk_name = 'test-disk-{}'.format(uuid.uuid4().hex)
336+
```
337+
338+
All temporary resources should be explicitly deleted when testing is
339+
complete. Use pytest's fixture for cleaning up these resouces instead
340+
of doing it in test itself.
327341

328342
### Console Output
329343

@@ -342,7 +356,7 @@ including the flake8 linter, Python 2.7, Python 3.x, and App Engine tests,
342356
as well as automated README generation.
343357

344358
__Note:__ As a temporary workaround, each project currently uses first
345-
`noxfile-template.py` found in a parent folder above the current sample. In
359+
`noxfile-template.py` found in a parent folder above the current sample. In
346360
order to simulate this locally, you need to copy + rename the parent
347361
`noxfile-template.py` as `noxfile.py` in the folder of the project you want to
348362
run tests.

0 commit comments

Comments
 (0)