Fix the problem with CDK's integ-runner breaking the python path and current working directory.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cdk_integ_runner_cwd_fix-0.1.1.tar.gz
.
File metadata
- Download URL: cdk_integ_runner_cwd_fix-0.1.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/5.15.49-linuxkit
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb87cd9e6eddedd18d3486ec8c7ad89858ea9a2a05ec84be3c1746bbd3173ed5 |
|
MD5 | 1adc318e3e9e3c1d5ab02e51209ea03d |
|
BLAKE2b-256 | 866baa175f0bf7358545300778375b9283741564784da9c65f0ad18b934115e0 |
File details
Details for the file cdk_integ_runner_cwd_fix-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: cdk_integ_runner_cwd_fix-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/5.15.49-linuxkit
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c038d7254a0bc2aa12d1178494951cc4fb8179de7800489a40c5da96ca2774e8 |
|
MD5 | 2a534e51866be34d1658a559a1327781 |
|
BLAKE2b-256 | 43cc12865a69841d172c8424d47cf2509292936523bf35f2bd8086965efae109 |