Hi all,
I wonder if I can enable/disable my own printing facilities based on whether the "-s" option is passed to pytest command line, as muting the printing still doesn't get rid of the overheads of printing (in my case very high ...). Is "-s" observable through some fixture or hacks? Or is it possble
to know the exact command line that invoked the test, so that I can search for "-s" on my own?
def test(print_on):
if print_on: print(xxx)
This is what I found in pytest source code.
group._addoption(
"-s",
action="store_const",
const="no",
dest="capture",
help="shortcut for --capture=no.",
)
Thanks,
Shunning
Hi @jsn1993,
Try using pytestconfig
def test(pytestconfig):
if pytestconfig.getoption("capture") != "no": print(xxx)
Hi @jsn1993,
Try using
pytestconfigdef test(pytestconfig): if pytestconfig.getoption("capture") != "no": print(xxx)
Thanks for the quick answer. It seems like the -s option won't change for a single Python execution, so is it possible to do it without fixture?
def test():
if pytestxxx.getoption("capture") != "no": print(xxx)
won't change for a single Python execution
What you mean, you are not running this with pytest?
Sorry I mean I prefer not to add fixture to every test function. Instead I wonder if it’s possible to get it without the fixture.
On Feb 12, 2020, at 17:20, Bruno Oliveira notifications@github.com wrote:

won't change for a single Python executionWhat you mean, you are not running this with pytest?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Oh I see, no currently there's no "global" access to pytest properties (we deliberately removed that support because it brought many initialization issues).
ok!
Thanks guys!