Default to UseAutomaticVirtualEnv in integration tests (#6318)

This way, the tests use the built-in virtual environment support by
default, which is what most customers will be using. A new `UsePipenv`
option is available to go back to using pipenv for tests.
This commit is contained in:
Justin Van Patten 2021-02-11 18:16:07 -08:00 committed by GitHub
parent f111a53337
commit d02c0b1152
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 39 deletions

View file

@ -21,6 +21,10 @@ CHANGELOG
- Look for `python` binary first on Windows instead of `python3`.
[#6317](https://github.com/pulumi/pulumi/pull/6317)
- [pkg/testing/integration] Change the default behavior for Python test projects to use `UseAutomaticVirtualEnv` by
default. `UsePipenv` can be set to go back to the old behavior of using pipenv with tests.
[#6318](https://github.com/pulumi/pulumi/pull/6318)
## 2.20.0 (2021-02-03)
- [sdk/python] Fix `Output.from_input` to unwrap nested output values in input types (args classes), which addresses

View file

@ -259,8 +259,11 @@ type ProgramTestOptions struct {
// Additional environment variables to pass for each command we run.
Env []string
// Automatically create and use a virtual environment, rather than using the Pipenv tool.
// Automatically create and use a virtual environment, rather than using the Pipenv tool. This is now the default
// behavior, so this option no longer has any affect. To go back to the old behavior use the `UsePipenv` option.
UseAutomaticVirtualEnv bool
// Use the Pipenv tool to manage the virtual environment.
UsePipenv bool
}
func (opts *ProgramTestOptions) GetDebugLogLevel() int {
@ -466,6 +469,9 @@ func (opts ProgramTestOptions) With(overrides ProgramTestOptions) ProgramTestOpt
if overrides.Env != nil {
opts.Env = append(opts.Env, overrides.Env...)
}
if overrides.UsePipenv {
opts.UsePipenv = overrides.UsePipenv
}
return opts
}
@ -781,7 +787,7 @@ func (pt *ProgramTester) runPulumiCommand(name string, args []string, wd string,
// the correct version of Python. We also need to do this for destroy and refresh so that
// dynamic providers are run in the right virtual environment.
// This is only necessary when not using automatic virtual environment support.
if !pt.opts.UseAutomaticVirtualEnv && isUpdate {
if pt.opts.UsePipenv && isUpdate {
projinfo, err := pt.getProjinfo(wd)
if err != nil {
return nil
@ -1741,7 +1747,11 @@ func (pt *ProgramTester) preparePythonProject(projinfo *engine.Projinfo) error {
return err
}
if pt.opts.UseAutomaticVirtualEnv {
if pt.opts.UsePipenv {
if err = pt.preparePythonProjectWithPipenv(cwd); err != nil {
return err
}
} else {
if err = pt.runPythonCommand("python-venv", []string{"-m", "venv", "venv"}, cwd); err != nil {
return err
}
@ -1753,11 +1763,7 @@ func (pt *ProgramTester) preparePythonProject(projinfo *engine.Projinfo) error {
}
if err := pt.runVirtualEnvCommand("virtualenv-pip-install",
[]string{"pip", "install", "-r", "requirements.txt"}, cwd); err != nil {
return err
}
} else {
if err = pt.preparePythonProjectWithPipenv(cwd); err != nil {
[]string{"python", "-m", "pip", "install", "-r", "requirements.txt"}, cwd); err != nil {
return err
}
}
@ -1813,14 +1819,14 @@ func (pt *ProgramTester) installPipPackageDeps(cwd string) error {
}
}
if pt.opts.UseAutomaticVirtualEnv {
if err := pt.runVirtualEnvCommand("virtualenv-pip-install-package",
[]string{"pip", "install", "-e", dep}, cwd); err != nil {
if pt.opts.UsePipenv {
if err := pt.runPipenvCommand("pipenv-install-package",
[]string{"run", "pip", "install", "-e", dep}, cwd); err != nil {
return err
}
} else {
if err := pt.runPipenvCommand("pipenv-install-package",
[]string{"run", "pip", "install", "-e", dep}, cwd); err != nil {
if err := pt.runVirtualEnvCommand("virtualenv-pip-install-package",
[]string{"python", "-m", "pip", "install", "-e", dep}, cwd); err != nil {
return err
}
}

View file

@ -23,8 +23,7 @@ func TestEmptyPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
})
}
@ -34,8 +33,7 @@ func TestStackOutputsPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// Ensure the checkpoint contains a single resource, the Stack, with two outputs.
fmt.Printf("Deployment: %v", stackInfo.Deployment)
@ -60,8 +58,7 @@ func TestConfigBasicPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
Config: map[string]string{
"aConfigValue": "this value is a Pythonic value",
},
@ -97,8 +94,7 @@ func TestStackReferencePython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
Config: map[string]string{
"org": os.Getenv("PULUMI_TEST_OWNER"),
},
@ -130,8 +126,7 @@ func TestMultiStackReferencePython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
Config: map[string]string{
"org": os.Getenv("PULUMI_TEST_OWNER"),
},
@ -163,8 +158,7 @@ func TestMultiStackReferencePython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
Config: map[string]string{
"org": os.Getenv("PULUMI_TEST_OWNER"),
"exporter_stack_name": exporterStackName,
@ -180,8 +174,7 @@ func TestResourceWithSecretSerializationPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// The program exports three resources:
// 1. One named `withSecret` who's prefix property should be secret, specified via `pulumi.secret()`.
@ -229,8 +222,7 @@ func TestPython3NotInstalled(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
Env: []string{
// Note: we use PULUMI_PYTHON_CMD to override the default behavior of searching
// for Python 3, since anyone running tests surely already has Python 3 installed on their
@ -254,7 +246,6 @@ func TestDynamicPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
randomVal = stack.Outputs["random_val"].(string)
},
@ -277,7 +268,6 @@ func TestPartialValuesPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
AllowEmptyPreviewChanges: true,
})
}
@ -289,7 +279,6 @@ func TestLargeResourcePython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
})
}
@ -300,7 +289,6 @@ func TestEnumOutputsPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stack.Outputs)
@ -339,8 +327,7 @@ func TestPythonPylint(t *testing.T) {
err := integration.RunCommand(t, "pylint", []string{pylint, "__main__.py"}, cwd, opts)
assert.NoError(t, err)
},
Quick: true,
UseAutomaticVirtualEnv: true,
Quick: true,
}
integration.ProgramTest(t, opts)
}
@ -367,8 +354,7 @@ func TestConstructPython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
Quick: true,
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
if assert.Equal(t, 9, len(stackInfo.Deployment.Resources)) {
@ -411,7 +397,6 @@ func TestGetResourcePython(t *testing.T) {
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
UseAutomaticVirtualEnv: true,
AllowEmptyPreviewChanges: true,
})
}

View file

@ -27,7 +27,6 @@ func TestPythonTypes(t *testing.T) {
assert.Equal(t, 42.0, stack.Outputs[fmt.Sprintf("res%s_second_value", res)])
}
},
UseAutomaticVirtualEnv: true,
})
})
}