CDK integ-runner CWD Fix
When running integ-test on python, the CWD is set to the directory which contains your test file - not the directory which contains your cdk.json.
It also blows away the PYTHONPATH, so that no longer has your cdk project.
This means that your test file has no access to the stacks you create, and you get a lot of ModuleNotFoundError when you try to import your stacks into the test case.
It also breaks the lambda (and likely other) builds which rely on a path. So,
If you're using Code.from_asset("./lambda") you should start using
Code.from_asset(f"{os.getcwd()}/lambda") instead, after using this fix.
This is likely to be applicable to other constructs that rely on a relative path.
This is a workaround to fix the CWD and PYTHONPATH so that your test file can import your stacks and run the integ tests.
Usage
Installation
pip install cdk-integ-runner-cwd-fix
In your code
Then, in your test file, add the following lines:
from cdk_integ_runner_cwd_fix import fix_cwd
fix_cwd()
# You can now import your stack
from my_cdk_project.my_stack import MyStack
# And write your test code here
app = cdk.App()
stack = MyStack(app, "TestStack")
app.synth()
Running tests
You'll need to set the project path in the environment variable CDK_INTEG_RUNNER_CWD:
The below will set it to your current directory - which is likely to be what you need:
export CDK_INTEG_RUNNER_CWD=$(pwd)
or to be explicit, or to set it to something other than the path you're currently in:
export CDK_INTEG_RUNNER_CWD=/path/to/your/cdk/project
Then, run your tests as usual:
integ-runner
Metadata
Release files for cdk-integ-runner-cwd-fix 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cdk_integ_runner_cwd_fix-0.1.1.tar.gz | 2.9 kB | Without provenance | Details for cdk_integ_runner_cwd_fix-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cdk_integ_runner_cwd_fix-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for cdk_integ_runner_cwd_fix-0.1.1-py3-none-any.whl |
Total release size: 6.4 kB
Release files / cdk_integ_runner_cwd_fix-0.1.1.tar.gz
| Download URL | cdk_integ_runner_cwd_fix-0.1.1.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb87cd9e6eddedd18d3486ec8c7ad89858ea9a2a05ec84be3c1746bbd3173ed5
|
|
BLAKE2b-256 checksum How to use checksums |
866baa175f0bf7358545300778375b9283741564784da9c65f0ad18b934115e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.0 Linux/5.15.49-linuxkit
|
Release files / cdk_integ_runner_cwd_fix-0.1.1-py3-none-any.whl
| Download URL | cdk_integ_runner_cwd_fix-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c038d7254a0bc2aa12d1178494951cc4fb8179de7800489a40c5da96ca2774e8
|
|
BLAKE2b-256 checksum How to use checksums |
43cc12865a69841d172c8424d47cf2509292936523bf35f2bd8086965efae109
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.0 Linux/5.15.49-linuxkit
|
Security for cdk-integ-runner-cwd-fix 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.