Pytest not selecting all tests from directory
Asked Answered
E

3

6

I'm trying to set up a continious integration for my GitLab project for the first time and I am struggling to get the 'test' stage working. Right now I have my test subfolder and 2 almost identical tests in it that should pass.

As I understand running the command pytest will run pytest on all test files it finds in current directory. The problem is only 1st problem is executing instead of all.

Here is the picture of the result from pipeline:

enter image description here

As you can see from the listing there are 2 files, but only the first one is tested.

What could have I missed here?

Eclipse answered 6/10, 2018 at 10:38 Comment(0)
V
15

Filenames should start or end with "test" word. Your second file name does not keep this requirement, so that's why pytest can't find it. You could check also this link

Veterinarian answered 6/10, 2018 at 11:0 Comment(1)
Thanks! Seems like I had missed this "little" fact. Changed test names and everything works fine now! =)Eclipse
P
0

Something I tried to do to figure this out was to run pytest --collect-only <directory_where_tests_are> and it told me what the issue was.

In my case the issue was that the test module required libraries that weren't installed, so pytest skips those files/directories.

Hope this helps!

Petr answered 24/8, 2023 at 4:20 Comment(0)
O
0

For this error, you should be careful in the file name as well as in the naming of the functions: For example, if my file name is test_simple, It is not my function, this naming must be respected:

def test_add_to():
    x = 2
    y = 3
    assert x + y == 5
Obedience answered 22/2 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.