Skip to content

Conversation

@pavoljuhas
Copy link
Collaborator

@pavoljuhas pavoljuhas commented Mar 13, 2023

test_notebooks_against_released_cirq should not change the installed
packages in the Python pytest environment. Adjust OS environment
so that pip invoked from tested notebooks installs to a temporary directory.
Also add test for changed packages that catches downgrade to ply==3.4
caused by a test of interop.ipynb.

test_notebooks_against_released_cirq should not change the installed
packages in the Python pytest environment.  Here we expose
downgrade of ply to ply==3.4 in the test of interop.ipynb.
@CirqBot CirqBot added the size: S 10< lines changed <50 label Mar 13, 2023
Execute papermill and notebook tests in an OS environment that
tells pip to install new packages to a temporary directory.
`pip install` commands in the notebook should thus not
change the environment that runs pytest.
@pavoljuhas pavoljuhas marked this pull request as ready for review March 13, 2023 21:12
@pavoljuhas pavoljuhas requested review from a team, cduck and vtomole as code owners March 13, 2023 21:12
@pavoljuhas pavoljuhas requested a review from maffoo March 13, 2023 21:13
@pavoljuhas pavoljuhas added the kind/health For CI/testing/release process/refactoring/technical debt items label Mar 13, 2023
pavoljuhas added a commit to pavoljuhas/Cirq that referenced this pull request Mar 13, 2023
Keep users safe from downgrading their ply package installed with cirq.

Related to quantumlib#6032
@pavoljuhas pavoljuhas requested a review from augustehirth March 21, 2023 18:38
Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a minor comment and a question to confirm the intended behavior.

packages_before = set((d.name, d.version) for d in importlib.metadata.distributions())
yield
packages_after = set((d.name, d.version) for d in importlib.metadata.distributions())
packages_changed = packages_before.difference(packages_after)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorter and more readable:

assert packages_before.issubset(packages_after)

or

assert packages_before == packages_after

for symmetric difference (see other comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, see the fix below.

packages_before = set((d.name, d.version) for d in importlib.metadata.distributions())
yield
packages_after = set((d.name, d.version) for d in importlib.metadata.distributions())
packages_changed = packages_before.difference(packages_after)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we actually want the symmetric difference here? IOW, don't we also want to prevent tests from changing the environment by installing new packages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Changed in e1d2ada.

Also fail if test_notebooks_against_released_cirq adds any new package.
Executions of `pip install` should deploy to a temporary directory.
@pavoljuhas pavoljuhas merged commit 0cc0458 into quantumlib:master Mar 23, 2023
@pavoljuhas pavoljuhas deleted the isolate-pip-in-notebook-test branch March 23, 2023 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/notebook-testing kind/health For CI/testing/release process/refactoring/technical debt items size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants