Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow deprecation for freezegun #3950

Merged
merged 8 commits into from
Mar 22, 2021

Conversation

balopat
Copy link
Contributor

@balopat balopat commented Mar 21, 2021

Allows usage of deprecated functionality for test functions leveraging freezegun.

During cirq.google migration this came up - as we don't have yet any deprecated attributes it didn't bite us.

Note: all other alternatives are significantly more complex, for example

  • we could make this more precise and introduce an env var specifically for the attributes
  • we could create a wrapper that removes all deprecated attributes before running these tests

@balopat balopat requested review from cduck, vtomole, wcourtney and a team as code owners March 21, 2021 23:33
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Mar 21, 2021
try:
return func(*args, **kwargs)
finally:
del os.environ[ALLOW_DEPRECATION_IN_TEST]
Copy link
Collaborator

Choose a reason for hiding this comment

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

If someone runs check/pytest with ALLOW_DEPRECATION_IN_TEST enabled in their environment, wouldn't this disable it for all subsequent tests? I think we need to capture its value prior to this test and reinstate the same value afterwards.

Copy link
Contributor Author

@balopat balopat Mar 22, 2021

Choose a reason for hiding this comment

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

It would, but it is not meant to be enabled for all tests, across the board, intentionally.
We have the cirq.testing.assert_deprecated context manager that allows for executing deprecated code. I do not want to make it easy to escape from running deprecated code in Cirq itself.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would, but it is not meant to be enabled for all tests, across the board, intentionally.

This won't stop devs from using it this way anyways 😛 . I found it useful to enable ALLOW_DEPRECATION_IN_TEST for the proto-serialization changes to separate deprecation failures from behavioral failures; I suspect other devs will use it this way as well.

Even if we don't want to treat this as a valid use case, I think it's worthwhile to guard against "spooky errors at a distance" like this. Unit tests should never fail due to the order in which they are run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This won't stop devs from using it this way anyways 😛 .

Those cheeky developers.

I found it useful to enable ALLOW_DEPRECATION_IN_TEST for the proto-serialization changes to separate deprecation failures from behavioral failures; I suspect other devs will use it this way as well.

Fair - being able to tackle piecemeal what is yelling at you sounds like a good feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit tests should never fail due to the order in which they are run.

That is a good point too. I'll revert to the previous state of it.

@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Mar 22, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Mar 22, 2021
@CirqBot CirqBot merged commit 13908f6 into quantumlib:master Mar 22, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants