How to avoid .pyc files using selenium webdriver/python while running test suites?
<p>There's no relevant answer to this question. When I run my test cases inside a test suite using selenium webdriver with python the directory gets trashed with .pyc files. They do not appear if I run test cases separately, only when I run them inside one test suite.How to avoid them?</p>

<pre><code>import unittest
from FacebookLogin import FacebookLogin
from SignUp import SignUp
from SignIn import SignIn

class TestSuite(unittest.TestSuite):
    def suite():
        suite = unittest.TestSuite()

        suite.addTest(FacebookLogin("test_FacebookLogin"))
        suite.addTest(SignUp("test_SignUp"))
        suite.addTest(SignIn("test_SignIn"))
        return suite

if __name__ == "__main__":
    unittest.main()
</code></pre>

<p><code>pyc</code> files are created any time you <code>import</code> a module, but not when you run a module directly as a script. That's why you're seeing them when you import the modules with the test code but don't see them created when you run the modules separately.</p>

<p>If you're invoking Python from the command line, you can suppress the creating of <code>pyc</code> files by using the <code>-B</code> argument. You can also set the environment variable <code>PYTHONDONTWRITEBYTECODE</code> with the same effect. I don't believe there's a way to change that setting with Python code after the interpreter is running.</p>

<p>In Python 3.2 and later, the <code>pyc</code> files get put into a separate <code>__pycache__</code> folder, which might be visually nicer. It also allows multiple <code>pyc</code> files to exist simultaneously for different interpreter versions that have incompatible bytecode (a "tag" is added to the file name indicating which interpreter uses each file).</p>

<p>But even in earlier versions of Python, I think that saying the <code>pyc</code> files are "trashing" the directory is a bit hyperbolic. Usually you can exempt the created files from source control (e.g. by listing <code>.pyc</code> in a <code>.gitignore</code> or equivalent file), and otherwise ignore them. Having <code>pyc</code> files around speeds up repeated imports of the file, since the interpreter doesn't need to recompile the source to bytecode if the <code>pyc</code> file already has the bytecode available.</p>

python selenium