You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that you do need to `pip install .` to get your changes under the `view` module. However, waiting for pip every time can be a headache. Unless you're modifying the [C API](https://github.com/ZeroIntensity/view.py/tree/master/src/_view), you don't actually need it. Instead, you can test your code via just importing from `src.view`. For example:
48
+
Note that you do need to `pip install .` to get your changes under the `view` module. However, waiting for pip every time can be a headache. Unless you're modifying the [C API](https://github.com/ZeroIntensity/view.py/tree/master/src/_view), you don't actually need it. Instead, you can test your code via just importing from `src.view`. A `test.py` file **should not** be inside of the `src/view` folder, but instead outside it (i.e. in the same directory as `src`).
49
+
50
+
For example, a simple `test.py` could look like:
47
51
48
52
```py
53
+
# test.py
49
54
from src.view import new_app
50
55
51
56
app = new_app()
@@ -57,6 +62,8 @@ async def index():
57
62
app.run()
58
63
```
59
64
65
+
**Note:** Import from `view` internally *does not* work when using `src.view`. Instead, your imports inside of view.py should look like `from .foo import bar`. For example, if you wanted to import `view.routing.get` from `src/view/app.py`, your import would look like `from .routing import get`
66
+
60
67
For debugging purposes, you're also going to want to disable `fancy` and `hijack` in the configuration:
61
68
62
69
```toml
@@ -65,6 +72,8 @@ fancy = false
65
72
hijack = false
66
73
```
67
74
75
+
These settings will stop view.py's fancy output from showing, as well as stopping the hijack of the `uvicorn` logger, and you'll get the raw `uvicorn` output.
76
+
68
77
## Writing Tests
69
78
70
79
**Note:** You do need to `pip install .` to update the tests, as they import from `view` and not `src.view`.
@@ -84,7 +93,7 @@ async def _():
84
93
85
94
asyncwith app.test() as test:
86
95
res =await test.get("/")
87
-
assert res.test=="test"
96
+
assert res.message=="test"
88
97
```
89
98
90
99
In the above code, a server **would not** be started, and instead just virtualized for testing purposes.
0 commit comments