Refactor common RPC test code to BitcoinTestFramework base class

Inspired by #3956, with a little more flexibility built in.

I didn't touch rpcbind_test.py, because it only runs on Linux.