Generate temporary file in a fixture
+import pytest
import textwrap
-def test_deprecation_warning_warns_correctly(script, tmpdir):
+@pytest.fixture
+def warnings_demo(tmpdir):
demo = tmpdir.joinpath('warnings_demo.py')
demo.write_text(textwrap.dedent('''
from logging import basicConfig
@@ -12,12 +14,15 @@ def test_deprecation_warning_warns_correctly(script, tmpdir):
deprecation.deprecated("deprecated!", replacement=None, gone_in=None)
'''))
+ return demo
- result = script.run('python', demo, expect_stderr=True)
+
+def test_deprecation_warnings_are_correct(script, warnings_demo):
+ result = script.run('python', warnings_demo, expect_stderr=True)
expected = 'WARNING:pip._internal.deprecations:DEPRECATION: deprecated!\n'
assert result.stderr == expected
# NOTE: PYTHONWARNINGS was added in 2.7
script.environ['PYTHONWARNINGS'] = 'ignore'
- result = script.run('python', demo)
+ result = script.run('python', warnings_demo)
assert result.stderr == ''
