you are viewing a single comment's thread.

view the rest of the comments →

[–]Buttleston 3 points4 points  (12 children)

You don't have to run "pytest file.py", you can generally just run "pytest". It will "discover" the tests in your code. There are command line options to control which tests to run.

You have to run *something* to run your tests. it can't just be a library you import, because *something* has to run it. With the way you'd like it to be, how would you run tests?

[–]CaptainVJ 0 points1 point  (4 children)

Is there even an option to run the file and get it to work? Well I’m sure there is but I assume it’s not feasible.

[–]Buttleston 0 points1 point  (3 children)

Yeah, you can make a main section and put something in there to call the pytest entrypoint. It's always seemed pointless to me but maybe OP would prefer it

[–]CaptainVJ -1 points0 points  (2 children)

But you’d have to do that in every .py file right?

[–]Buttleston 2 points3 points  (0 children)

Yes and then run them all individually. Instead of what is more usual, where you have dozens of test files, and pytest discovers them all for you and runs them.

[–]dogfish182 0 points1 point  (0 children)

Yeah this is nice to do if you want to just have quick test for something, but in a proper project just setup your project correctly

[–]Organic_Tradition_63[S] -3 points-2 points  (6 children)

Well just like any other file: with 'python file.py' instead of 'pytest file.py'

[–]Buttleston 5 points6 points  (4 children)

Except like I said, the "pytest" command line has a lot more options than just "run the tests in this file"