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

pytest: fix mocker as context manager and setenv test warnings #695

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

mattseddon
Copy link
Member

@mattseddon mattseddon commented Aug 31, 2023

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™


Fixes issue of the format:

  /dvclive/tests/test_dvc.py:160: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=None):

&

  /dvclive/tests/test_main.py:229: PytestWarning: Value of environment variable DVCLIVE_RESUME type should be str, but got True (type: bool); converted to str implicitly
    monkeypatch.setenv(env.DVCLIVE_RESUME, True)

Result of pytest -v tests --ignore=tests/test_frameworks:

Before

Log
================================================================================================================================================ warnings summary ================================================================================================================================================
tests/test_dvc.py::test_exp_save_skip_on_env_vars
  /dvclive/tests/test_dvc.py:160: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=None):

tests/test_dvc.py::test_exp_save_run_on_dvc_repro
  /dvclive/tests/test_dvc.py:179: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo):

tests/test_dvc.py::test_exp_save_with_dvc_files
  /dvclive/tests/test_dvc.py:221: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo):

tests/test_dvc.py::test_no_scm_repo
  /dvclive/tests/test_dvc.py:319: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo):

tests/test_main.py::test_resume_env_var
  /dvclive/tests/test_main.py:229: PytestWarning: Value of environment variable DVCLIVE_RESUME type should be str, but got True (type: bool); converted to str implicitly
    monkeypatch.setenv(env.DVCLIVE_RESUME, True)

tests/test_report.py::test_make_report_open
  /dvclive/tests/test_report.py:125: PytestWarning: Value of environment variable DVCLIVE_OPEN type should be str, but got True (type: bool); converted to str implicitly
    monkeypatch.setenv(DVCLIVE_OPEN, True)

tests/test_vscode.py::test_vscode_dvclive_step_completed_signal_file[True]
  /dvclive/tests/test_vscode.py:22: PytestWarning: Value of environment variable DVC_ROOT type should be str, but got PosixPath('/private/var/folders/sb/fqcw44jd19nfrhl_9lz_81d80000gn/T/pytest-of/pytest-138/test_vscode_dvclive_step_compl0') (type: PosixPath); converted to str implicitly
    monkeypatch.setenv(env.DVC_ROOT, tmp_dir)

tests/test_vscode.py::test_vscode_dvclive_step_completed_signal_file[True]
tests/test_vscode.py::test_vscode_dvclive_step_completed_signal_file[False]
  /dvclive/tests/test_vscode.py:33: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo), mocker.patch(

tests/test_vscode.py::test_vscode_dvclive_only_signal_file[True]
tests/test_vscode.py::test_vscode_dvclive_only_signal_file[False]
  /dvclive/tests/test_vscode.py:78: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo), mocker.patch(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Results (4.52s):
     174 passed

After

Results (4.75s):
     174 passed

@codecov-commenter
Copy link

Codecov Report

Patch coverage is 100.00% of modified lines.

Files Changed Coverage
tests/test_dvc.py 100.00%
tests/test_main.py 100.00%
tests/test_report.py 100.00%
tests/test_vscode.py 100.00%

πŸ“’ Thoughts on this report? Let us know!.

@mattseddon mattseddon marked this pull request as ready for review August 31, 2023 00:19
@mattseddon mattseddon requested review from daavoo and dberenbaum and removed request for daavoo August 31, 2023 00:19
Copy link
Contributor

@daavoo daavoo left a comment

Choose a reason for hiding this comment

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

πŸ”₯

@daavoo daavoo merged commit d5859f2 into main Aug 31, 2023
11 checks passed
@daavoo daavoo deleted the clean-test-warnings branch August 31, 2023 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants