vy32
vy32

Reputation: 29655

py.test test discovery for a test in a file that does not begin test_*.py

I am new to py.test and want to simply write some test functions next to some other functions in a Python file.

My main file is called something like myfile.py. Inside that file I have a function. For example:

def pad(bytes):
    return " "*bytes

I want to verify the behavior of the function:

def test_pad():
    assert pad(3)=="   "

The problem is my test_pad() function never runs. It does run if I put it in a file called test_myfile.py and that file does an import, but that seems like a lot of overhead.

Whats the proper way to do this?

Upvotes: 0

Views: 128

Answers (1)

vy32
vy32

Reputation: 29655

Create a file called pytest.ini:

[pytest]
python_files=*.py

See Changing standard (Python) test discovery for more details. (It's not that obvious.)

Upvotes: 1

Related Questions