Clojure

Add a way to access the current test var in :each fixtures for clojure.test

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

When looking at (log) output from tests written with clojure.test, I would like to be able to identify the output associated with each test. A mechanism to expose the current test var within an :each fixture would enable this.

One mechanism might be to bind a test-var var with the current test var before calling the each-fixture-fn in clojure.test/test-all-vars.

  1. add-test-var.diff
    21/Oct/11 10:34 PM
    3 kB
    Hugo Duncan
  2. clj840-2.diff
    25/Oct/11 6:26 PM
    2 kB
    Stuart Sierra

Activity

Hide
Stuart Sierra added a comment -

Or just pass the Var directly into the fixture. Vars are invokable.

Show
Stuart Sierra added a comment - Or just pass the Var directly into the fixture. Vars are invokable.
Hide
Hugo Duncan added a comment - - edited

I don't think that works, since the the function passed to the fixture is not the test var, but a function calling test-var on the test var.

Show
Hugo Duncan added a comment - - edited I don't think that works, since the the function passed to the fixture is not the test var, but a function calling test-var on the test var.
Hide
Hugo Duncan added a comment -

Patch to add test-var

Show
Hugo Duncan added a comment - Patch to add test-var
Hugo Duncan made changes -
Field Original Value New Value
Attachment add-test-var.diff [ 10495 ]
Hide
Stuart Sierra added a comment - - edited

*testing-vars* already has this information, but it's not visible to the fixture functions because it gets bound inside test-var.

Perhaps the :each fixture functions should be called in test-var rather than in test-all-vars. (The namespace of a Var is available in its metadata.) But then we have to call join-fixtures inside test-var every time.

Show
Stuart Sierra added a comment - - edited *testing-vars* already has this information, but it's not visible to the fixture functions because it gets bound inside test-var. Perhaps the :each fixture functions should be called in test-var rather than in test-all-vars. (The namespace of a Var is available in its metadata.) But then we have to call join-fixtures inside test-var every time.
Hide
Stuart Sierra added a comment -

Try this patch: clj840-2.diff.

This makes *testing-vars* visible to :each fixture functions, which seems intuitively more correct.

BUT it slightly changes the behavior of test-var, which I'm less happy about.

Show
Stuart Sierra added a comment - Try this patch: clj840-2.diff. This makes *testing-vars* visible to :each fixture functions, which seems intuitively more correct. BUT it slightly changes the behavior of test-var, which I'm less happy about.
Stuart Sierra made changes -
Attachment clj840-2.diff [ 10497 ]
Stuart Sierra made changes -
Assignee Stuart Sierra [ stuart.sierra ]
Hide
Hugo Duncan added a comment -

Might it make sense to provide a function on top of testing-vars to return the current test-var?

Show
Hugo Duncan added a comment - Might it make sense to provide a function on top of testing-vars to return the current test-var?
Hide
Stuart Sierra added a comment -

No, that function is first

Show
Stuart Sierra added a comment - No, that function is first
Hide
Hugo Duncan added a comment -

I agree with having the dynamic vars as part of the extension interface, but would have thought that having a function for use when writing tests would have been cleaner. Just my 2c.

Show
Hugo Duncan added a comment - I agree with having the dynamic vars as part of the extension interface, but would have thought that having a function for use when writing tests would have been cleaner. Just my 2c.
Stuart Sierra made changes -
Assignee Stuart Sierra [ stuart.sierra ]
Andy Fingerhut made changes -
Patch Code [ 10001 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: