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

Check that we can serialize the warning detail attr #379

Merged
merged 7 commits into from Jan 11, 2019

Conversation

aadamson
Copy link
Contributor

@aadamson aadamson commented Nov 21, 2018

Thanks for submitting a PR, your contribution is really appreciated!

Here's a quick checklist that should be present in PRs:

  • Make sure to include reasonable tests for your change if necessary

  • We use towncrier for changelog management, so please add a news file into the changelog folder following these guidelines:

    • Name it $issue_id.$type for example 588.bugfix;

    • If you don't have an issue_id change it to the PR id after creating it

    • Ensure type is one of removal, feature, bugfix, vendor, doc or trivial

    • Make sure to use full sentences with correct case and punctuation, for example:

      Fix issue with non-ascii contents in doctest text files.
      

I was running into the same issue addressed in #349, except instead of failing to serialize an arg of the warning, I was unable to serialize a warning detail of the warning. To reproduce the error, you can cause a ResourceWarning due to an unclosed socket. One of the warning details will be the socket that wasn't closed, which can't be serialized.

This PR addresses the issue by performing the same check as #349.

@nicoddemus
Copy link
Member

Thanks a lot @aadamson!


sigh oh boy do I regret having the idea of transferring warning instances between master and workers.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

LGTM, but can you please provide a regression test for this?

See

def test_unserializable_arguments(self, testdir, n):
for an example that you can base a new test on.

@aadamson
Copy link
Contributor Author

@nicoddemus My pleasure! I think it's a really cool feature :)

I'll add that test now

@nicoddemus
Copy link
Member

Awesome, thanks!

aadamson added a commit to aadamson/pytest-xdist that referenced this pull request Nov 21, 2018
@aadamson
Copy link
Contributor Author

Do you guys have a guide on running the tests locally?

@nicoddemus
Copy link
Member

Take a look at pytest's guide it is the same for pytest-xdist (we use tox to run the tests).

Please let us know if you run into trouble. 👍

aadamson added a commit to aadamson/pytest-xdist that referenced this pull request Nov 29, 2018
@aadamson
Copy link
Contributor Author

aadamson commented Jan 7, 2019

@nicoddemus picking this back up - I can't repro the issue (or rather, I can't figure out how to construct a test that will replicate the failure, so I can't check if the failure is handled properly). Would you be okay if I only address testing the feature in Python 3 in this PR?

@nicoddemus
Copy link
Member

Would you be okay if I only address testing the feature in Python 3 in this PR?

Go ahead, we can try to help out to reproduce on Python 2. 👍

aadamson added a commit to aadamson/pytest-xdist that referenced this pull request Jan 8, 2019
@aadamson
Copy link
Contributor Author

aadamson commented Jan 8, 2019

I'm seeing TestWarnings.test_warnings fail in CI with

____________________ TestWarnings.test_warnings[pytest--n0] ____________________
self = <acceptance_test.TestWarnings instance at 0x7f51f5a4bcb0>
testdir = <Testdir local('/tmp/pytest-of-travis/pytest-0/test_warnings0')>
n = '-n0', warn_type = 'pytest'
    @pytest.mark.parametrize("n", ["-n0", "-n1"])
    @pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
    def test_warnings(self, testdir, n, warn_type):
        if warn_type == "builtin":
            warn_code = """warnings.warn(UserWarning('this is a warning'))"""
        elif warn_type == "pytest":
            warn_code = """request.config.warn('', 'this is a warning',
                           fslocation=py.path.local())"""
        else:
            assert False
        testdir.makepyfile(
            """
            import warnings, py, pytest
    
            @pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
            def test_func(request):
                {warn_code}
        """.format(
                warn_code=warn_code
            )
        )
        result = testdir.runpytest(n)
>       result.stdout.fnmatch_lines(["*this is a warning*", "*1 passed, 1 warnings*"])
E       Failed: nomatch: '*this is a warning*'
E           and: u'============================= test session starts =============================='
E           and: u'platform linux2 -- Python 2.7.14, pytest-4.1.0, py-1.7.0, pluggy-0.8.0'
E           and: u'rootdir: /tmp/pytest-of-travis/pytest-0/test_warnings0, inifile:'
E           and: u'plugins: xdist-1.25.1.dev6+g08c2387, forked-0.2'
E           and: u'collected 1 item'
E           and: u''
E           and: u'test_warnings.py F                                                       [100%]'
E           and: u''
E           and: u'=================================== FAILURES ==================================='
E           and: u'__________________________________ test_func ___________________________________'
E           and: u''
E           and: u'request = <FixtureRequest for <Function test_func>>'
E           and: u''
E           and: u"    @pytest.mark.filterwarnings('ignore:config.warn has been deprecated')"
E           and: u'    def test_func(request):'
E       fnmatch: '*this is a warning*'
E          with: u">       request.config.warn('', 'this is a warning',"
E       nomatch: '*1 passed, 1 warnings*'
E           and: u'                   fslocation=py.path.local())'
E           and: u"E       AttributeError: 'Config' object has no attribute 'warn'"
E           and: u''
E           and: u'test_warnings.py:5: AttributeError'
E           and: u'=========================== 1 failed in 0.01 seconds ==========================='
E           and: u''
E       remains unmatched: '*1 passed, 1 warnings*'

but I can't find where the request fixture is defined to investigate further. Do you know where it is, or why I'd see this error in CI but not locally?

@nicoddemus
Copy link
Member

Oh we need to update the test suite for 4.1.0. I will do it in a separate PR.

@nicoddemus
Copy link
Member

@aadamson you can merge/rebase on master to fix the Config.warn tests. 👍

@aadamson
Copy link
Contributor Author

aadamson commented Jan 8, 2019

Done, thank you!

testing/acceptance_test.py Outdated Show resolved Hide resolved
xdist/remote.py Outdated Show resolved Hide resolved
changelog/379.bugfix.rst Outdated Show resolved Hide resolved
@nicoddemus
Copy link
Member

Awesome, thank you!

@aadamson
Copy link
Contributor Author

Thanks for your help! How do I merge?

@nicoddemus
Copy link
Member

Only the maintainers can merge. 😁

I didn't merge yet in case @RonnyPfannschmidt wants to take a look first.

@nicoddemus nicoddemus merged commit c3dbd05 into pytest-dev:master Jan 11, 2019
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