
import os
import re
import sys

from _common import unittest

pkgpath = os.path.dirname(__file__) or '.'
sys.path.append(pkgpath)
os.chdir(pkgpath)

def suite():
    s = unittest.TestSuite()
    # Get the suite() of every module in this directory beginning with
    # "test_".
    for fname in os.listdir(pkgpath):
        match = re.match(r'(test_\S+)\.py$', fname)
        if match:
            modname = match.group(1)
            s.addTest(__import__(modname).suite())
    return s

if __name__ == '__main__':
    unittest.main(defaultTest='suite')


import os
import re
import sys

from _common import unittest

pkgpath = os.path.dirname(__file__) or '.'
sys.path.append(pkgpath)
os.chdir(pkgpath)

# Make sure we use local version of beetsplug and not system namespaced version
# for tests
try:
    del sys.modules["beetsplug"]
except KeyError:
    pass

def suite():
    s = unittest.TestSuite()
    # Get the suite() of every module in this directory beginning with
    # "test_".
    for fname in os.listdir(pkgpath):
        match = re.match(r'(test_\S+)\.py$', fname)
        if match:
            modname = match.group(1)
            s.addTest(__import__(modname).suite())
    return s

if __name__ == '__main__':
    unittest.main(defaultTest='suite')

Fix python namespaces for test runs
Fix python namespaces for test runs

We need to make sure we don't use namespaced versions that are already installed
on the system but rather use local version from current sources

  
  import os
  import re
  import sys
  
  from _common import unittest
  
  pkgpath = os.path.dirname(__file__) or '.'
  sys.path.append(pkgpath)
  os.chdir(pkgpath)
+ 
+ # Make sure we use local version of beetsplug and not system namespaced version
+ # for tests
+ try:
+     del sys.modules["beetsplug"]
+ except KeyError:
+     pass
  
  def suite():
      s = unittest.TestSuite()
      # Get the suite() of every module in this directory beginning with
      # "test_".
      for fname in os.listdir(pkgpath):
          match = re.match(r'(test_\S+)\.py$', fname)
          if match:
              modname = match.group(1)
              s.addTest(__import__(modname).suite())
      return s
  
  if __name__ == '__main__':
      unittest.main(defaultTest='suite')
  
Fix python namespaces for test runs
## Code Before:

import os
import re
import sys

from _common import unittest

pkgpath = os.path.dirname(__file__) or '.'
sys.path.append(pkgpath)
os.chdir(pkgpath)

def suite():
    s = unittest.TestSuite()
    # Get the suite() of every module in this directory beginning with
    # "test_".
    for fname in os.listdir(pkgpath):
        match = re.match(r'(test_\S+)\.py$', fname)
        if match:
            modname = match.group(1)
            s.addTest(__import__(modname).suite())
    return s

if __name__ == '__main__':
    unittest.main(defaultTest='suite')

## Instruction:
Fix python namespaces for test runs
## Code After:

import os
import re
import sys

from _common import unittest

pkgpath = os.path.dirname(__file__) or '.'
sys.path.append(pkgpath)
os.chdir(pkgpath)

# Make sure we use local version of beetsplug and not system namespaced version
# for tests
try:
    del sys.modules["beetsplug"]
except KeyError:
    pass

def suite():
    s = unittest.TestSuite()
    # Get the suite() of every module in this directory beginning with
    # "test_".
    for fname in os.listdir(pkgpath):
        match = re.match(r'(test_\S+)\.py$', fname)
        if match:
            modname = match.group(1)
            s.addTest(__import__(modname).suite())
    return s

if __name__ == '__main__':
    unittest.main(defaultTest='suite')
