Skip to content

Commit a232b7c

Browse files
author
Israel Fruchter (ifruchte)
committed
changeing to automaticly build the .png output, if graphvis available in path
1 parent 81f96a5 commit a232b7c

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

README.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Output can look like this:
5050
You can also generate the usage fixture graph like that:
5151

5252
.. sourcecode::
53+
# on windows gitbash as example
54+
export PATH=$PATH:/c/Program\ Files\ \(x86\)/Graphviz2.38/bin/
5355
pytest --fixture-graph -s
5456

5557
The Output would be like that:
@@ -67,8 +69,7 @@ The Output would be like that:
6769
tests\conftest.py . [ 57%]
6870
tests\test_fixture_duplicates.py .
6971
-------------------------------- fixture-graph --------------------------------
70-
created at artifacts/fixture-graph-tests-test_fixture_duplicates.py__test_there_are_not_fixture_duplicates.dot.
71-
You can convert it to a PNG using 'dot -Tpng artifacts/fixture-graph-tests-test_fixture_duplicates.py__test_there_are_not_fixture_duplicates.dot -o artifacts/fixture-graph-tests-test_fixture_duplicates.py__test_there_are_not_fixture_duplicates.png'
72+
created artifacts/fixture-graph-tests-test_fixture_duplicates.py__test_there_are_fixture_duplicates.png.
7273
============================= test session starts =============================
7374
platform win32 -- Python 2.7.10, pytest-3.3.1, py-1.5.2, pluggy-0.6.0
7475
rootdir: c:\users\ifruchte\appdata\local\temp\pytest-of-ifruchte\pytest-445\test_there_are_not_fixture_duplicates0, inifile:
@@ -80,11 +81,6 @@ The Output would be like that:
8081

8182
===================== 6 passed, 1 skipped in 0.29 seconds =====================
8283

83-
And running the hinted command:
84-
85-
.. sourcecode::
86-
dot -Tpng artifacts/fixture-graph-tests-test_fixture_duplicates.py__test_there_are_not_fixture_duplicates.dot -o artifacts/fixture-graph-tests-test_fixture_duplicates.py__test_there_are_not_fixture_duplicates.png
87-
8884
would provide this output, that can help under a test that depend on large amount of fixtures:
8985

9086
.. image:: imgs/graph_example.png

imgs/graph_example.png

17.5 KB
Loading

pytest_fixture_tools/plugin.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@ def pytest_addoption(parser):
3232
group.addoption('--fixture',
3333
action="store", type=str, dest="fixture_name", default='',
3434
help="Name of specific fixture for which you want to get duplicates")
35+
3536
group.addoption('--fixture-graph',
3637
action="store_true", dest="fixture_graph", default=False,
3738
help="create .dot fixture graph for each test")
39+
group.addoption('--fixture-graph-output-dir',
40+
action="store_true", dest="fixture_graph_output_dir", default="artifacts",
41+
help="select the location for the output of fixture graph. defaults to 'artifacts'")
42+
group.addoption('--fixture-graph-output-type',
43+
action="store_true", dest="fixture_graph_output_type", default="png",
44+
help="select the type of the output for the fixture graph. defaults to 'png'")
3845

3946

4047
def pytest_cmdline_main(config):
@@ -138,11 +145,17 @@ def pytest_runtest_setup(item):
138145
edge = pydot.Edge(node, i)
139146
graph.add_edge(edge)
140147

141-
log_dir = os.environ.get('LOG_DEST_DIR', 'artifacts')
148+
log_dir = item.config.option.fixture_graph_output_dir
149+
output_type = item.config.option.fixture_graph_output_type
142150
mkdir_recursive(log_dir)
143151
filename = "{0}/fixture-graph-{1}".format(log_dir, item._nodeid.replace(":", "_").replace("/", "-"))
144-
graph.write(filename + ".dot")
145152
tw.line()
146153
tw.sep("-", "fixture-graph")
147-
tw.line("created at {}.dot.".format(filename))
148-
tw.line("You can convert it to a PNG using 'dot -Tpng {0}.dot -o {0}.png'".format(filename))
154+
try:
155+
graph.write("{}.{}".format(filename, output_type), format=output_type)
156+
tw.line("created {}.{}.".format(filename, output_type))
157+
except Exception:
158+
tw.line("grpahvis wasn't found in PATH")
159+
graph.write(filename + ".dot")
160+
tw.line("created {}.dot.".format(filename))
161+
tw.line("You can convert it to a PNG using:\n\t'dot -Tpng {0}.dot -o {0}.png'".format(filename))

tests/test_fixtrue_graph.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,5 @@ def arg1(request):
2424

2525
result = testdir.runpytest_subprocess('--fixture-graph', '-s')
2626

27-
result.stdout.fnmatch_lines("created at artifacts/fixture-graph-sub1-test_in_sub1.py__test_1.dot.")
28-
result.stdout.fnmatch_lines("You can convert it to a PNG using 'dot -Tpng artifacts/fixture-graph-sub1"
29-
"-test_in_sub1.py__test_1.dot -o artifacts/fixture-graph-sub1-test_in_sub1"
30-
".py__test_1.png'")
31-
32-
result.stdout.fnmatch_lines("created at artifacts/fixture-graph-sub1-sub2-test_in_sub2.py__test_2.dot.")
33-
result.stdout.fnmatch_lines("You can convert it to a PNG using 'dot -Tpng artifacts/fixture-graph-sub1"
34-
"-sub2-test_in_sub2.py__test_2.dot -o artifacts/fixture-graph-sub1-sub2-te"
35-
"st_in_sub2.py__test_2.png'")
27+
result.stdout.fnmatch_lines("created artifacts/fixture-graph-sub1-test_in_sub1.py__test_1.dot.")
28+
result.stdout.fnmatch_lines('created artifacts/fixture-graph-sub1-sub2-test_in_sub2.py__test_2.dot.')

0 commit comments

Comments
 (0)