How to mock string as content of file for pytest?
I wrote a pytest plugin called pytest_tmp_files to solve this exact problem.  Here's how it would look for your example:
@pytest.mark.parametrize(
    'tmp_files', [
        {'f': '#'},
        {'f': '##'},
        {'f': ''},
        {'f': '   '},
        {'f': '  '},
    ],
    indirect=['tmp_files'],
)
def test_is_input_file_valid(tmp_files):
    assert t.myclass(tmp_files / 'f')

Some things worth noting:

The parameters are dictionaries where the keys are file names and the values are files contents.  This is a bit more verbose that just specifying the file contents, but much more flexible.
I'm assuming that your parser accepts pathlib.Path objects, which is what tmp_files / 'f' is.  If not, you might have to do some sort of conversion here, but it should be straight forward.
The specified files are actually created in a real temporary directory (unique for each test case), so you can treat them exactly like real files.
I wrote another pytest plugin called parametrize_from_file that allows you to specify test parameters in structured data files (e.g. YAML), separate from the test code.  I'd recommend checking it out as well.  File contents often end up being long, multi-line strings that mess up the indentation of the parameter list and make the whole test script hard to read.  Moving these parameters to a separate file can really help readability.

See also this discussion on GitHub, where I tried to get this feature added to pytest proper.

How can I provide string to function in pytest, so that function under test treat it as content of file ?
I have function that is parsing file. File is custom text format.
I want to test multiple different input files.
Initial idea was to use pytest is this way:
import pytest
import mymodule as t

# this is all valid one line config file, starting simple
@pytest.mark.parametrize("input_file", [
    "#",
    "##",
    "",
    "   ",
    "  ",
])

def test_is_input_file_valid(input_file):
    assert t.myclass(input_file)

Problem that I have is each line need to be content of input file, because t.myclass(input_file) is expecting file not string. So, I need somehow to mock it.
I am assuming pytest have this functionality by default or plugin, but was not able to find it.
