Skip to content

Fixed #31370 -- Added support for parallel tests with --buffer. - #12580

Merged
felixxm merged 3 commits into
django:mainfrom
adamchainz:ticket_31370
Mar 18, 2021
Merged

felixxm merged 3 commits into
django:mainfrom
adamchainz:ticket_31370

Conversation

@adamchainz

Copy link
Copy Markdown
Member

@adamchainz

Copy link
Copy Markdown
Member Author

I've also added a commit to make the runtests.py script always use buffer mode.

Tbh I'm in favour of making buffer the default for all users. We could add an --unbuffer option to flip it off. This is the default behaviour of pytest and it can speed up tests quite a bit since writing output to screen can become a limiting factor.

@adamchainz

Copy link
Copy Markdown
Member Author

Paging @bmispelon for review since you wrote the first buffer PR #12169.

Comment thread django/test/runner.py Resolved

@bmispelon bmispelon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This subclassing approach seems a lot more clean to me. I think it's the right one.

I've suggested two minor changes but they're not blocking at all.

I don't have an opinion on the change to make buffer the default (or for forcing it to True for runtests.py).

Comment thread django/test/runner.py Resolved
Comment thread django/test/runner.py Resolved
@adamchainz adamchainz changed the title Fixed #31370 -- Added support for parallel tests with --buffer Fixed #31370 -- Added support for parallel tests with --buffer. May 6, 2020
@adamchainz

Copy link
Copy Markdown
Member Author

Rebased. I also made a ticket to propose making buffering the default, with a --no-buffer option to disable it: https://code.djangoproject.com/ticket/31543#ticket .

@adamchainz

Copy link
Copy Markdown
Member Author

@Valze you may also be interested to see or review this PR, since it's test runner related.

Comment thread django/test/runner.py Resolved
@lothemar

lothemar commented May 8, 2020 •

Copy link
Copy Markdown
Contributor

@Valze you may also be interested to see or review this PR, since it's test runner related.

I've been keeping an eye on it ever since you started solving it initially a month and a half ago. I'll give it a more thorough read over this weekend and see if I can help in any way.

@lothemar

Copy link
Copy Markdown
Contributor

Code looks much cleaner after subclassing TextResult, and it really does improve a lot of other written methods.

I'm +1 on setting buffer as the default option. It removes unnecessary clutter

@adamchainz

Copy link
Copy Markdown
Member Author

I'm +1 on setting buffer as the default option. It removes unnecessary clutter

Thanks. Can you repeat that on the ticket ?

@felixxm felixxm left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@adamchainz Thanks 👍

IMO we shouldn't change the current behavior of runtests.py I find it valuable, so I would recommend to chop the second commit. Lets be honest we "all" use print() in tests to check sth 😄. Folks who are concerned here can add the flag. (It's not much of a burden.)

Comment thread django/test/runner.py Resolved
Comment thread django/test/runner.py Resolved
Comment thread django/test/runner.py Resolved
Comment thread django/test/runner.py Resolved
Comment thread django/test/runner.py Resolved
)
with self.assertRaisesMessage(ValueError, msg):
DiscoverRunner(buffer=True, parallel=2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add a test? similar to the test_buffer_mode_test_pass().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried:

    def test_buffer_mode_parallel(self):
        runner = DiscoverRunner(parallel=2, buffer=True, verbose=0)
        with captured_stdout() as stdout, captured_stderr() as stderr:
            suite = runner.build_suite([
                'test_runner_apps.buffer.tests_buffer.WriteToStdoutStderrTestCase.test_pass',
                'test_runner_apps.buffer.tests_buffer.WriteToStdoutStderrTestCase2.test_pass',
            ])
            runner.run_suite(suite)
        self.assertNotIn('Write to stderr.', stderr.getvalue())
        self.assertNotIn('Write to stdout.', stdout.getvalue())

But this doesn't work because we can't capture stdin/stdout across the parallel processes. Any suggestions?

Comment thread tests/test_runner/test_parallel.py Resolved
@felixxm

felixxm commented Nov 11, 2020

Copy link
Copy Markdown
Member

@adamchainz Do you have time to check my comments and polish this patch?

Base automatically changed from master to main March 9, 2021 06:21
@adamchainz
adamchainz force-pushed the ticket_31370 branch 2 times, most recently from e761da7 to da4815c Compare March 16, 2021 12:48
@adamchainz

Copy link
Copy Markdown
Member Author

I finally got back to this.

@felixxm

felixxm commented Mar 17, 2021

Copy link
Copy Markdown
Member

@adamchainz Thanks for updates 👍 I still believe that we should drop the last commit and keep the current (default) behavior for runtests.py, see comment.

@carltongibson Can I ask for your opinion?

@felixxm felixxm self-assigned this Mar 17, 2021
@carltongibson
carltongibson self-requested a review March 17, 2021 07:42
@adamchainz

Copy link
Copy Markdown
Member Author

I'm happy to drop the last commit if you think so, but I have not seen any pytest users complain about its automatic buffering. You can always do print() + assert 0 to see the output.

@carltongibson carltongibson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, please, can we not change the behaviour of ./runtests.py here. (-s is amongst my favourite pytest options.)

Otherwise looks good.

@adamchainz

Copy link
Copy Markdown
Member Author

Okay I dropped the change to runtests.py

@felixxm felixxm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@adamchainz Thanks for updates 👍 I pushed edits to the first two commits and noticed one issue.

Comment thread django/test/runner.py Resolved
@felixxm

felixxm commented Mar 18, 2021

Copy link
Copy Markdown
Member

@adamchainz Also, it doesn't really work for me. I think you missed passing buffer to the RemoteTestResult. I pushed commit with a proposed fix.

@adamchainz

Copy link
Copy Markdown
Member Author

I think you missed passing buffer to the RemoteTestResult. I pushed commit with a proposed fix.

Ah thanks. I think I accidentally dropped that in the rebase-and-split.

@felixxm

felixxm commented Mar 18, 2021

Copy link
Copy Markdown
Member

I noticed that signature are outdated, see #14145.

@felixxm

felixxm commented Mar 18, 2021

Copy link
Copy Markdown
Member

@adamchainz Thanks 👍 It's ready to go 🌟

@felixxm
felixxm merged commit f6713cd into django:main Mar 18, 2021
@adamchainz
adamchainz deleted the ticket_31370 branch March 18, 2021 15:40
@adamchainz

Copy link
Copy Markdown
Member Author

🙌 🚀

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.

5 participants