Skip to content

Instantly share code, notes, and snippets.

@nicoddemus
Created November 22, 2016 12:44
Show Gist options
  • Save nicoddemus/7ab1d515c6b758ec1b4e466503e7d8a4 to your computer and use it in GitHub Desktop.
Save nicoddemus/7ab1d515c6b758ec1b4e466503e7d8a4 to your computer and use it in GitHub Desktop.
Generates dummy test tree
"""
Creates a dummy tree with test files, with or without conftest.py files.
Usage:
generate_tests_tree.py 4 6 10 0
Generates a tree 4 levels deep, 6 folders per level and 10 test files each, without any conftest.py files. Each
test file contains 10 dummy tests.
"""
import os
import sys
import shutil
levels, folders, tests, conftests = sys.argv[1:]
if os.path.isdir('root'):
shutil.rmtree('root')
os.mkdir('root')
for level_index in range(int(levels)):
level_folder = 'root/pkg%d' % level_index
os.mkdir(level_folder)
with open(level_folder + '/__init__.py', 'w') as f:
pass
for folder_index in range(int(folders)):
directory = level_folder + '/mod%s' % folder_index
os.mkdir(directory)
with open(directory + '/__init__.py', 'w') as f:
pass
for test_index in range(int(tests)):
if int(conftests):
with open('%s/conftest.py' % directory, 'w') as conftest_file:
pass
with open('%s/test_%d.py' % (directory, test_index), 'w') as test_file:
code = (
"import pytest\n"
"@pytest.mark.parametrize('i', range(10))\n"
"def test(i): pass\n"
)
test_file.write(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment