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

Display the filename when encountering SyntaxWarning. #4153

Merged
merged 1 commit into from
Oct 15, 2018
Merged

Display the filename when encountering SyntaxWarning. #4153

merged 1 commit into from
Oct 15, 2018

Conversation

asottile
Copy link
Member

@asottile asottile commented Oct 14, 2018

Resolves #4152

Couldn't think of a way to test this without implementation / version specific code 🤷‍♂️ -- at least the commit message contains the reproduction

before

$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
.                                                                        [100%]
=============================== warnings summary ===============================
<unknown>:2: DeprecationWarning: invalid escape sequence \.

-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds

after

$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
.                                                                        [100%]
=============================== warnings summary ===============================
/tmp/pytest/t/t.py:2: DeprecationWarning: invalid escape sequence \.
  '\.wat'

-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds

```console
$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
.                                                                        [100%]
=============================== warnings summary ===============================
<unknown>:2: DeprecationWarning: invalid escape sequence \.

-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds

```

```console
$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
.                                                                        [100%]
=============================== warnings summary ===============================
/tmp/pytest/t/t.py:2: DeprecationWarning: invalid escape sequence \.
  '\.wat'

-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds
```
@nicoddemus
Copy link
Member

Couldn't think of a way to test this without implementation / version specific code

What do you mean? A test which at least checks that the filename and DeprecationWarning is appearing is OK I think. If the problem is Python 2/Python 3, I think having separate tests is fine.

@asottile
Copy link
Member Author

Couldn't think of a way to test this without implementation / version specific code

What do you mean? A test which at least checks that the filename and DeprecationWarning is appearing is OK I think. If the problem is Python 2/Python 3, I think having separate tests is fine.

The only SyntaxWarnings I know of are:

assert(1, 2)   # pytest has special handling for this already

def test():
    x = 5   # assignment before `global` statement, a `SyntaxError` in py3+
    global x

'\.'  # SyntaxError in python3.8+, not a warning in python<3.6

any way I'd write this would become obsolete at some point

@coveralls
Copy link

coveralls commented Oct 15, 2018

Coverage Status

Coverage increased (+0.02%) to 94.014% when pulling 2e42d93 on asottile:syntax_warning_filename into 49defa2 on pytest-dev:master.

@nicoddemus
Copy link
Member

I see. Well, better than nothing I guess. 😁

Can you take a look at the Travis failure please?

@asottile
Copy link
Member Author

hmm, passes locally:

============ 2141 passed, 111 skipped, 11 xfailed in 38.73 seconds =============
___________________________________ summary ____________________________________
  py27-nobyte: commands succeeded
  congratulations :)

going to click retry -- I suspect some sort of race with xdist / coverage :S

@asottile
Copy link
Member Author

Here's the error message in case we hit it again:

__________________ TestArgComplete.test_compare_with_compgen ___________________
[gw31] linux2 -- Python 2.7.6 /home/travis/build/pytest-dev/pytest/.tox/py27-nobyte/bin/python
self = <test_argcomplete.TestArgComplete object at 0x7fb82d7821d0>
    @pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
    def test_compare_with_compgen(self):
        from _pytest._argcomplete import FastFilesCompleter
    
        ffc = FastFilesCompleter()
        fc = FilesCompleter()
        for x in ["/", "/d", "/data", "qqq", ""]:
>           assert equal_with_bash(x, ffc, fc, out=sys.stdout)
E           AssertionError: assert False
E            +  where False = equal_with_bash('', <_pytest._argcomplete.FastFilesCompleter object at 0x7fb82d782290>, <test_argcomplete.FilesCompleter object at 0x7fb82d7822d0>, out=<_pytest.capture.EncodedFile object at 0x7fb82f04c6d0>)
E            +    where <_pytest.capture.EncodedFile object at 0x7fb82f04c6d0> = sys.stdout
testing/test_argcomplete.py:96: AssertionError
----------------------------- Captured stdout call -----------------------------
equal_with_bash True ['/.bin-lib.SHA256SUMS', '/.dockerenv', '/.dpkg-manifest.json', '/.job-board-register.yml', '/.node-attributes.yml', '/.packer-env/', '/bin/', '/boot/', '/dev/', '/etc/', '/home/', '/lib/', '/lib64/', '/media/', '/mnt/', '/opt/', '/packer-files/', '/proc/', '/root/', '/run/', '/sbin/', '/srv/', '/sys/', '/tmp/', '/usr/', '/var/']
equal_with_bash True ['/dev/']
equal_with_bash True []
equal_with_bash True []
equal_with_bash False ['.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.2908.830164', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.2909.941892', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.2915.970571', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.2921.419086', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.2926.839619', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.2931.802132', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3375.680637', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3376.100482', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3377.813990', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3378.091396', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3379.311001', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3384.835829', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3385.672248', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3389.771183', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3425.656835', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3476.407434', '.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3481.313609', '.coveragerc', '.eggs/', '.git/', '.gitattributes', '.github/', '.gitignore', '.hypothesis/', '.pre-commit-config.yaml', '.tox/', '.travis.yml', 'AUTHORS', 'CHANGELOG.rst', 'CITATION', 'CONTRIBUTING.rst', 'HOWTORELEASE.rst', 'LICENSE', 'README.rst', 'appveyor.yml', 'bench/', 'changelog/', 'doc/', 'extra/', 'pyproject.toml', 'scripts/', 'setup.cfg', 'setup.py', 'src/', 'testing/', 'tox.ini']
 python - bash: set([])
 bash - python: set([u'.coverage.travis-job-pytest-dev-pytest-441428406.travisci.net.3390.185518'])

@asottile
Copy link
Member Author

passed 🤷‍♂️

@asottile asottile merged commit 093e19a into pytest-dev:master Oct 15, 2018
@asottile asottile deleted the syntax_warning_filename branch October 15, 2018 15:40
@nicoddemus
Copy link
Member

Weird, OK let's keep an eye on it. 👍

@nicoddemus
Copy link
Member

Ouch it happened again:

__________________ TestArgComplete.test_compare_with_compgen ___________________
[gw3] linux2 -- Python 2.7.6 /home/travis/build/pytest-dev/pytest/.tox/py27-nobyte/bin/python
self = <test_argcomplete.TestArgComplete object at 0x7f6da5d3a7d0>
    @pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
    def test_compare_with_compgen(self):
        from _pytest._argcomplete import FastFilesCompleter
    
        ffc = FastFilesCompleter()
        fc = FilesCompleter()
        for x in ["/", "/d", "/data", "qqq", ""]:
>           assert equal_with_bash(x, ffc, fc, out=sys.stdout)
E           AssertionError: assert False
E            +  where False = equal_with_bash('', <_pytest._argcomplete.FastFilesCompleter object at 0x7f6da5d881d0>, <test_argcomplete.FilesCompleter object at 0x7f6da5d88150>, out=<_pytest.capture.EncodedFile object at 0x7f6da6f9cbd0>)
E            +    where <_pytest.capture.EncodedFile object at 0x7f6da6f9cbd0> = sys.stdout
testing/test_argcomplete.py:96: AssertionError

https://travis-ci.org/pytest-dev/pytest/jobs/441861559

😢

@nicoddemus
Copy link
Member

Created an issue: #4162

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.

3 participants