Metadata-Version: 2.1
Name: cdk-integ-runner-cwd-fix
Version: 0.1.1
Summary: Fix the problem with CDK's integ-runner breaking the python path and current working directory.
Home-page: https://github.com/tomharvey/cdk-integ-runner-cwd-fix
License: MIT
Keywords: cdk,aws-cdk,aws,testing,test
Author: Tom Harvey
Author-email: tom@alush.co.uk
Requires-Python: >=3.8,<4.0
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Documentation
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Project-URL: Repository, https://github.com/tomharvey/cdk-integ-runner-cwd-fix
Description-Content-Type: text/markdown

# 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

``` bash
pip install cdk-integ-runner-cwd-fix
```


### In your code

Then, in your test file, add the following lines:

```python
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:

```bash
export CDK_INTEG_RUNNER_CWD=$(pwd)
```

or to be explicit, or to set it to something other than the path you're currently in:

```bash
export CDK_INTEG_RUNNER_CWD=/path/to/your/cdk/project
```

Then, run your tests as usual:

```bash
integ-runner
```
