Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest object has no attribute 'main' #281

Closed
pytestbot opened this issue Mar 21, 2013 · 5 comments
Closed

pytest object has no attribute 'main' #281

pytestbot opened this issue Mar 21, 2013 · 5 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Jason Lee (BitBucket: tutong, GitHub: tutong)


I copied the code in pytest usage.html#pytest-main-usage as followed:

import pytest
class MyPlugin:
    def pytest_sessionfinish(self):
        print("*** test run reporting finishing")

pytest.main("-qq", plugins=[MyPlugin()])

into a file named mytest_1.py and then execute "python mytest_1.py"
I got the result:

 **Traceback (most recent call last):
  File "mytest_1.py", line 7, in <module>
    pytest.main("-qq", plugins=[MyPlugin()])
AttributeError: 'module' object has no attribute 'main'**

and the expected is:
*** test run reporting finishing

py.test information :py.test version 2.3.4, imported from /usr/local/lib/python2.7/site-packages/pytest.pyc
python information:Python 2.7.3
system information:Linux 2.6.32.16-141.1.x86_64 #1 SMP Wed Jul 14 22:04:02 CST 2010 x86_64 x86_64 x86_64 GNU/Linux


@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


made description readable

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


i cant replicate

as a sidenote, you need to pass a list into

also try pytest.cmdline.main

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


do a print pytest after the import to see where it's comming from.

@pytestbot
Copy link
Contributor Author

Original comment by Jason Lee (BitBucket: tutong, GitHub: tutong):


printed pytest and I got

#!python

<module 'pytest' from '/home/tutong/testing.frame/py_test/pytest.pyc'>

I tried pytest.cmdline.main and got

#!python

Traceback (most recent call last):
  File "mytest_1.py", line 8, in <module>
    pytest.cmdline.main("-qq", plugins=[MyPlugin()])
AttributeError: 'module' object has no attribute 'cmdline'

the same as before.

It looks my local path

Should I reinstall pytest?

@pytestbot
Copy link
Contributor Author

Original comment by Jason Lee (BitBucket: tutong, GitHub: tutong):


I change the file by mistake.

After re-installed it, all is ok

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
These 2 options allow you to pass in regular expressions that determine
whether files/directories are included or excluded in the recursive file
search.

Fixes pytest-dev#270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant