check for stdout.encoding before doing encoding in pytest
use or syntax instead of if statements
Move sys.stdout.encoding to top of function
Merge pull request #1698 from eteq/fix-pytest-stdout-encoding

check for stdout.encoding before doing encoding in pytest