Skip to content

Commit

Permalink
Pass arguments to pytest; Plot tests skippable
Browse files Browse the repository at this point in the history
Added ability to pass command line arguments to pytest.
In addition, I marked tests which do plotting as 'plottest'.
This combination allows the following invocation:

    python -m lifelines.tests -m "not plottest"

Which will skip plotting tests. Any arguments that pytests
accepts can be passed now.

Signed-off-by: Jonas Kalderstam <[email protected]>
  • Loading branch information
spacecowboy committed Dec 7, 2014
1 parent c7244fc commit a6c333e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lifelines/tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

if __name__ == '__main__':
# Exit with correct code
sys.exit(pytest.main("--pyargs lifelines.tests"))
sys.exit(pytest.main(["--pyargs", "lifelines.tests"] + sys.argv[1:]))
4 changes: 4 additions & 0 deletions lifelines/tests/test_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def test_kmf_left_censorship_stats(self):
assert kmf.cumulative_density_[kmf._label].ix[0] == 0.0
assert kmf.cumulative_density_[kmf._label].ix[12] == 1.0

@pytest.mark.plottest
@pytest.mark.skipif("DISPLAY" not in os.environ, reason="requires display")
def test_kmf_left_censorship_plots(self):
kmf = KaplanMeierFitter()
Expand Down Expand Up @@ -662,6 +663,7 @@ def test_large_dimensions_for_recursion_error(self):
aaf = AalenAdditiveFitter()
aaf.fit(X)

@pytest.mark.plottest
@pytest.mark.skipif("DISPLAY" not in os.environ, reason="requires display")
def test_aaf_panel_dataset(self):
panel_dataset = load_panel_test()
Expand All @@ -688,6 +690,7 @@ def test_aalen_additive_median_predictions_split_data(self):
T_pred = aaf.predict_median(X[list(range(6))])
assert abs((T_pred.values > T).mean() - 0.5) < 0.05

@pytest.mark.plottest
@pytest.mark.skipif("DISPLAY" not in os.environ, reason="requires display")
def test_aalen_additive_fit_no_censor(self):
# this is a visual test of the fitting the cumulative
Expand All @@ -713,6 +716,7 @@ def test_aalen_additive_fit_no_censor(self):
plt.show()
return

@pytest.mark.plottest
@pytest.mark.skipif("DISPLAY" not in os.environ, reason="requires display")
def test_aalen_additive_fit_with_censor(self):
# this is a visual test of the fitting the cumulative
Expand Down
1 change: 1 addition & 0 deletions lifelines/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..plotting import plot_lifetimes


@pytest.mark.plottest
@pytest.mark.skipif("DISPLAY" not in os.environ, reason="requires display")
class TestPlotting():

Expand Down

0 comments on commit a6c333e

Please sign in to comment.