Skip to content

Commit ee90255

Browse files
authored
docs: poly test (#17)
* docs: poly test
1 parent a39ad25 commit ee90255

File tree

2 files changed

+27
-143
lines changed

2 files changed

+27
-143
lines changed

docs/commands.md

Lines changed: 24 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -483,142 +483,60 @@ Show brick depencencies for a specific project.
483483
`--brick`
484484
A detailed view for a single brick and the dependent bricks: used by, and uses.
485485

486-
## Testing
487-
Example, how to run __pytest__ for changed bricks only.
486+
## Test
487+
Polylith doesn't have its own test runner. Use your favorite testing tool, such as `pytest`.
488488

489-
#### Poetry
490-
``` shell
491-
# store the comma-separated list of bricks in a bash variable
492-
changes="$(poetry poly diff --bricks --short)"
493-
494-
# transform it into a pytest query,
495-
# i.e. from "hello,world,something" to "hello or world or something"
496-
query="${changes//,/ or }"
497-
```
489+
### Running tests
490+
See the [testing](testing.md) section for examples on how to run __pytest__ for changed bricks only.
498491

499-
Run the test, filtered by keyword expression
500-
501-
``` shell
502-
poetry run pytest -k <<< echo "$query"
503-
```
492+
### Test diff
493+
With the `poly test` command, You can identify the bricks and projects that are _affected_ by changes in tests.
494+
The `poly test` command is used with a sub-command: __poly test diff__.
495+
It will show you any affected bricks or projects a test is modified.
504496

505-
or run the test, filtered by pytest markers
497+
Tests are expected to live in a test folder at the Workspace root when using the recommended __loose__ theme.
498+
For users of the __tdd__ theme, the tests are expected to be found in the brick test folder.
506499

500+
#### Poetry
507501
``` shell
508-
poetry run pytest -m <<< echo "$query"
502+
poetry poly test diff
509503
```
510504

511505
#### Hatch
512506
``` shell
513-
# store the comma-separated list of bricks in a bash variable
514-
changes="$(hatch run poly diff --bricks --short)"
515-
516-
# transform it into a pytest query,
517-
# i.e. from "hello,world,something" to "hello or world or something"
518-
query="${changes//,/ or }"
519-
```
520-
521-
Run the test, filtered by keyword expression
522-
523-
``` shell
524-
hatch run pytest -k <<< echo "$query"
525-
```
526-
527-
or run the test, filtered by pytest markers
528-
529-
``` shell
530-
hatch run pytest -m <<< echo "$query"
507+
hatch run poly test diff
531508
```
532509

533510
#### PDM
534511
``` shell
535-
# store the comma-separated list of bricks in a bash variable
536-
changes="$(pdm run poly diff --bricks --short)"
537-
538-
# transform it into a pytest query,
539-
# i.e. from "hello,world,something" to "hello or world or something"
540-
query="${changes//,/ or }"
541-
```
542-
543-
Run the test, filtered by keyword expression
544-
545-
``` shell
546-
pdm run pytest -k <<< echo "$query"
547-
```
548-
549-
or run the test, filtered by pytest markers
550-
551-
``` shell
552-
pdm run pytest -m <<< echo "$query"
512+
pdm run poly test diff
553513
```
554514

555515
#### Rye
556516
``` shell
557-
# store the comma-separated list of bricks in a bash variable
558-
changes="$(rye run poly diff --bricks --short)"
559-
560-
# transform it into a pytest query,
561-
# i.e. from "hello,world,something" to "hello or world or something"
562-
query="${changes//,/ or }"
563-
```
564-
565-
Run the test, filtered by keyword expression
566-
567-
``` shell
568-
rye run pytest -k <<< echo "$query"
569-
```
570-
571-
or run the test, filtered by pytest markers
572-
573-
``` shell
574-
rye run pytest -m <<< echo "$query"
517+
rye run poly test diff
575518
```
576519

577520
#### uv
578521
``` shell
579-
# store the comma-separated list of bricks in a bash variable
580-
changes="$(uv run poly diff --bricks --short)"
581-
582-
# transform it into a pytest query,
583-
# i.e. from "hello,world,something" to "hello or world or something"
584-
query="${changes//,/ or }"
585-
```
586-
587-
Run the test, filtered by keyword expression
588-
589-
``` shell
590-
uv run pytest -k <<< echo "$query"
591-
```
592-
593-
or run the test, filtered by pytest markers
594-
595-
``` shell
596-
uv run pytest -m <<< echo "$query"
522+
uv run poly test diff
597523
```
598524

599525
#### Maturin
600526
``` shell
601527
# if not already activated a virtual environment
602528
source .venv/bin/activate
603-
```
604529

605-
``` shell
606-
# store the comma-separated list of bricks in a bash variable
607-
changes="$(poly diff --bricks --short)"
608-
609-
# transform it into a pytest query,
610-
# i.e. from "hello,world,something" to "hello or world or something"
611-
query="${changes//,/ or }"
530+
poly test diff
612531
```
613532

614-
Run the test, filtered by keyword expression
533+
### Options
534+
`--short` Useful for determining what projects has been affected by the changes in CI.
615535

616-
``` shell
617-
pytest -k <<< echo "$query"
618-
```
536+
`--bricks` Useful for displaying affected bricks only. It will print a comma-separated list of bricks when using it with the `--short` option.
619537

620-
or run the test, filtered by pytest markers
538+
`--projects` Useful for displaying affected projects only. It will print a comma-separated list of projects when using it with the `--short` option.
621539

622-
``` shell
623-
pytest -m <<< echo "$query"
624-
```
540+
`--since` Useful for displaying changes since a `stable` or `release` tag.
541+
The tag patterns are defined in the Workspace [configuration](configuration.md).
542+
This option also support using a specific commit hash.

docs/testing.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,7 @@ This [is optional and can be turned off](configuration.md) in the Workspace conf
88
The tests are added in a `test` folder at the root of the workspace with the same kind of folder structure as the bricks.
99

1010
### Example
11-
Creating a new `parser` component. This will add a new brick to the `components` folder.
12-
13-
#### Poetry
14-
``` shell
15-
poetry poly create component --name parser
16-
```
17-
18-
#### Hatch
19-
``` shell
20-
hatch run poly create component --name parser
21-
```
22-
23-
#### PDM
24-
``` shell
25-
pdm run poly create component --name parser
26-
```
27-
28-
#### Rye
29-
``` shell
30-
rye run poly create component --name parser
31-
```
32-
33-
#### uv
34-
``` shell
35-
uv run poly create component --name parser
36-
```
37-
38-
#### Maturin
39-
``` shell
40-
# if not already activated a virtual environment
41-
source .venv/bin/activate
42-
43-
poly create component --name parser
44-
```
45-
11+
Creating a new `parser` component using `poly create component`. This will add a new brick.
4612
A corresponding unit test will also be created in the `test` folder:
4713
``` python
4814
from my_top_namespace.parser import core
@@ -103,8 +69,8 @@ addopts = [
10369
```
10470

10571
### Running tests for changed code
106-
The __Python tools__ for the Polylith Architecture doesn't (yet) have a specific `test` command.
107-
You can use `poly diff` and your favorite test runner to only run the corresponding tests for changed code.
72+
You can use `poly diff` in combination with your favorite test runner,
73+
to only run the corresponding tests for changed code.
10874

10975
The `diff` command has support for displaying the changed bricks by using `--bricks`.
11076
Append the `--short` option for a scripting-friendly output.

0 commit comments

Comments
 (0)