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

Add option to silence deprecation warnings when running the tests #2948

Open
stefannibrasil opened this issue Apr 30, 2024 · 4 comments · May be fixed by #2956
Open

Add option to silence deprecation warnings when running the tests #2948

stefannibrasil opened this issue Apr 30, 2024 · 4 comments · May be fixed by #2956

Comments

@stefannibrasil
Copy link
Contributor

We have recently introduced an internal deprecator for faker. See #2858 and #2919 for more details.

We'd like to have the option to skip printing out the deprecation warnings when running the tests. Currently, we get a long test output due to them.

Ruby's Deprecate gem has the option to wrap a test assertion in a skip_during block, intended to be used in the test suite only:

class TestSomething < Gem::Testcase
  def test_some_thing_with_deprecations
    Gem::Deprecate.skip_during do
      actual_stdout, actual_stderr = capture_output do
        Gem.something_deprecated
      end
      assert_empty actual_stdout
      assert_equal(expected, actual_stderr)
    end
  end
end

It would be nice if we could have a similar option for our custom deprecator so our test output is not filled with those deprecation messages while they are being removed.

@keshavbiswa
Copy link
Contributor

Let me try it.

@stefannibrasil
Copy link
Contributor Author

awesome, thank you!

@keshavbiswa
Copy link
Contributor

So there are two approaches I see here,

  1. To use class accessors to capture stdouts only when the variable is true, (skip_during will yield and ensure it's set to false after)? This makes it easy to turn it on/off for individual tests, depending on what we want to assert?
  2. The other is to globally disable in in test_helper.rb, this is an easier approach, but makes it difficult to enable/disable individual tests.

@stefannibrasil Lmk what you think.

@stefannibrasil
Copy link
Contributor Author

hi @keshavbiswa thanks for working on this. Yeah, number 1 seems to be what we need. We want to be able to skip the output when explicitly adding a skip block. If we add the block is because we know the test will generate the warning but there's nothing we can do until the generator is removed/updated, if that makes sense.

@keshavbiswa keshavbiswa linked a pull request May 22, 2024 that will close this issue
6 tasks
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 a pull request may close this issue.

2 participants