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

fix: request recording in unittest setUp method #338

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

zermelo-wisen
Copy link
Collaborator

Fixes #332

  • Hooks unittest TestCase._callSetUp method to disable request recording in order to prevent the creation of a request recording when a request is made inside setUp method of a unittest test.
  • Adds a unittest test to django fixture project which makes a request inside setUp method. This test makes the test_django.py::TestDjangoApp::test_enabled pass with the fix and fail without the fix.
  • This edge case can be observed in this test in django project:
    $ APPMAP=TRUE ./runtests.py auth_tests.test_views.ChangelistTests.test_user_change_email
    A request made inside ChangelistTests.setUp method leads to the creation of requests recording AppMap without the fix.

@kgilpin kgilpin added the bug Something isn't working label Jun 7, 2024
@apotterri apotterri self-requested a review June 16, 2024 10:56
@@ -213,7 +213,7 @@ def test_enabled(self, pytester):
def test_disabled(self, pytester, monkeypatch):
monkeypatch.setenv("_APPMAP", "false")
result = pytester.runpytest("-svv", "-p", "no:randomly", "-k", "test_request")
result.assert_outcomes(passed=1, failed=0, errors=0)
result.assert_outcomes(passed=2, failed=0, errors=0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also needs to check that no request recordings were created.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't the following line assert that as well?

assert not (pytester.path / "tmp").exists()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, it does, in the case that APPMAP=false (i.e. recording is completely disabled). The test I asked for ensures that request recordings aren't generated when other AppMaps are.

@zermelo-wisen zermelo-wisen force-pushed the fix/request-recording-in-unittest-setup branch from f90ca45 to 1ee69cb Compare June 21, 2024 06:26
Copy link
Collaborator

@apotterri apotterri left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

@apotterri apotterri merged commit ab2770e into master Jun 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

request recordings generated when testing Django
3 participants