pulumi/pkg/testing/integration
Justin Van Patten 92abd1a9ef
ProgramTest: Python: Use correct venv path for projects with `main` option (#15225)
In preparation for supporting Python 3.12...

I'm planning to remove `pulumi` from `requirements.txt` in a bunch of
the integration tests (at least temporarily) because the current
published version of `pulumi` can't be installed on Python 3.12 due to
its dependency on `grpcio` which is broken on Python 3.12, and the tests
specify a dependency on the locally built Pulumi Python SDK via
`ProgramTestOptions.Dependencies`.

However, after removing `pulumi` from `requirements.txt` for
`TestPythonStackTruncate/main_dir_specified`, the test started to fail
due to a missing `pulumi` package. It shouldn't fail because the test
additionally requires the locally built SDK via
`ProgramTestOptions.Dependencies`.

The reason for the failure is because this test had a `main` specified
in the project to a sub directory (`bar/`). Because of this, the venv
created by `ProgramTest` is inside the sub directory. It would install
the `requirements.txt` in that venv, and then install any
`ProgramTestOptions.Dependencies` deps. Then it would record the
`virtualenv` option in the project as just `venv`. But this option is
relative to the project file and a `venv` directory next to the project
doesn't exist -- it exists in the sub directory.

So when the first `pulumi` operation was run, `pulumi` would see that
the `venv` directory next to the project doesn't exist, and create it,
installing the dependencies from `requirements.txt` in it and carrying
on.

With the change to remove `pulumi` from `requirements.txt` for this
test, this would no longer work. When `pulumi` created the venv, it'd
install an empty `requirements.txt` in the venv it created. And since it
didn't have a `pulumi` package, it fails with a missing module.

This change fixes `ProgramTest` to record the correct path to the venv
in the project file. In most cases, this continues to be just `venv`.
But if `main` is specified in the project such that the "cwd" path is
different from the project file root, then that path is used for the
venv. This way, the CLI will use the correct venv that includes
dependencies from `ProgramTestOptions.Dependencies`.
2024-01-23 23:21:02 +00:00
..
command.go Don't disable ambiant providers during tests (#9404) 2022-04-15 11:14:47 +02:00
doc.go Document Go packages (#6009) 2021-01-11 11:07:59 -07:00
program.go ProgramTest: Python: Use correct venv path for projects with `main` option (#15225) 2024-01-23 23:21:02 +00:00
program_test.go Attempt to run Windows tests on small runners (#15070) 2024-01-05 21:44:04 +00:00
pulumi.go Enable perfsprint linter (#14813) 2023-12-12 12:19:42 +00:00
s3reporter.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
util.go Enable perfsprint linter (#14813) 2023-12-12 12:19:42 +00:00