Jossy
Jossy

Reputation: 1007

How do I fix PytestAssertRewriteWarning?

I'm just starting out with pytest and pytest_mysql and have the following code:

import pytest
from pytest_mysql import factories

if __name__ == "__main__":
    pytest.main([r'test.py', '-v'])
    testdb = factories.mysql('testdb')

This generates a warning:

PytestAssertRewriteWarning: Module already imported so cannot be rewritten: pytest_mysql
  1. Should I be concerned?
  2. How can I ensure I don't get the warning?

Upvotes: 2

Views: 2578

Answers (1)

Daniel Exxxe
Daniel Exxxe

Reputation: 69

This is how i solved it!

import pytest
if __name__=='__main__': #Note 1
    pytest.main()
#
#Your code goes here
#
from pytest_mysql import factories
testdb = factories.mysql('testdb')

So try running pytest.main() before you import anything else..

Note 1

That's not the usual way you call __name__=='__main__', but as it works i buy it!

Upvotes: 2

Related Questions