# Help with deprecation warnings in tests

**URL:** https://discourse.julialang.org/t/help-with-deprecation-warnings-in-tests/50011
**Category:** New to Julia
**Created:** [November 11, 2020, 11:44pm UTC](https://discourse.julialang.org/t/help-with-deprecation-warnings-in-tests/50011 "2020-11-11T23:44:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [November 11, 2020, 11:44pm UTC](https://discourse.julialang.org/t/help-with-deprecation-warnings-in-tests/50011/1 "2020-11-11T23:44:16Z")

</div>

I would like to test that a function emits a deprecation warning, but I keep getting errors. Can someone please help me get the right syntax? Here is an MWE

```julia
julia> function foo()
       Base.depwarn("use an argument", :foo; force = true)
       1
       end
foo (generic function with 2 methods)

julia> function foo(x)
       1
       end
foo (generic function with 2 methods)

julia> foo()
┌ Warning: use an argument
│ caller = top-level scope at REPL[31]:1
└ @ Core REPL[31]:1
1

julia> @test_warn "use an argument" foo()
┌ Warning: use an argument
│ caller = #32 at Test.jl:633 [inlined]
└ @ Core /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Test/src/Test.jl:633
Test Failed at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Test/src/Test.jl:636
  Expression: contains_warn(read(fname, String), $(Expr(:escape, "use an argument")))
ERROR: There was an error during testing

```

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [November 12, 2020, 7:49am UTC](https://discourse.julialang.org/t/help-with-deprecation-warnings-in-tests/50011/2 "2020-11-12T07:49:51Z")

</div>

Looking at the documentation, [`@test_warn`](https://docs.julialang.org/en/v1/stdlib/Test/#Test.@test_warn) can’t test warnings generated with `@warn`. You could use `@test_logs` instead:

```julia
julia> @test_logs (:warn, "use an argument") foo()
1

```

(you should also be able to use [`@test_deprecated`](https://docs.julialang.org/en/v1/stdlib/Test/#Test.@test_deprecated) in this situation, but then I think your message would have to be formatted more like deprecation warnings coming from `@deprecate`)
